<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>16.1. os — Miscellaneous operating system interfaces &mdash; Python v2.6.2 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.6.2',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python v2.6.2 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python v2.6.2 documentation" href="../index.html" />
    <link rel="up" title="16. Generic Operating System Services" href="allos.html" />
    <link rel="next" title="16.2. io — Core tools for working with streams" href="io.html" />
    <link rel="prev" title="16. Generic Operating System Services" href="allos.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="io.html" title="16.2. io — Core tools for working with streams"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="allos.html" title="16. Generic Operating System Services"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="allos.html" accesskey="U">16. Generic Operating System Services</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-os">
<h1>16.1. <tt class="xref docutils literal"><span class="pre">os</span></tt> &#8212; Miscellaneous operating system interfaces<a class="headerlink" href="#module-os" title="Permalink to this headline">¶</a></h1>
<p>This module provides a portable way of using operating system dependent
functionality.  If you just want to read or write a file see <a title="open" class="reference external" href="functions.html#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a>, if
you want to manipulate paths, see the <a title="Operations on pathnames." class="reference external" href="os.path.html#module-os.path"><tt class="xref docutils literal"><span class="pre">os.path</span></tt></a> module, and if you want to
read all the lines in all the files on the command line see the <a title="Loop over standard input or a list of files." class="reference external" href="fileinput.html#module-fileinput"><tt class="xref docutils literal"><span class="pre">fileinput</span></tt></a>
module.  For creating temporary files and directories see the <a title="Generate temporary files and directories." class="reference external" href="tempfile.html#module-tempfile"><tt class="xref docutils literal"><span class="pre">tempfile</span></tt></a>
module, and for high-level file and directory handling see the <a title="High-level file operations, including copying." class="reference external" href="shutil.html#module-shutil"><tt class="xref docutils literal"><span class="pre">shutil</span></tt></a>
module.</p>
<p>The design of all built-in operating system dependent modules of Python is such
that as long as the same functionality is available, it uses the same interface;
for example, the function <tt class="docutils literal"><span class="pre">os.stat(path)</span></tt> returns stat information about
<em>path</em> in the same format (which happens to have originated with the POSIX
interface).</p>
<p>Extensions peculiar to a particular operating system are also available through
the <tt class="xref docutils literal"><span class="pre">os</span></tt> module, but using them is of course a threat to portability!</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If not separately noted, all functions that claim &#8220;Availability: Unix&#8221; are
supported on Mac OS X, which builds on a Unix core.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">All functions in this module raise <a title="exceptions.OSError" class="reference external" href="exceptions.html#exceptions.OSError"><tt class="xref docutils literal"><span class="pre">OSError</span></tt></a> in the case of invalid or
inaccessible file names and paths, or other arguments that have the correct
type, but are not accepted by the operating system.</p>
</div>
<dl class="exception">
<dt id="os.error">
<em class="property">
exception </em><tt class="descclassname">os.</tt><tt class="descname">error</tt><a class="headerlink" href="#os.error" title="Permalink to this definition">¶</a></dt>
<dd>An alias for the built-in <a title="exceptions.OSError" class="reference external" href="exceptions.html#exceptions.OSError"><tt class="xref docutils literal"><span class="pre">OSError</span></tt></a> exception.</dd></dl>

<dl class="data">
<dt id="os.name">
<tt class="descclassname">os.</tt><tt class="descname">name</tt><a class="headerlink" href="#os.name" title="Permalink to this definition">¶</a></dt>
<dd>The name of the operating system dependent module imported.  The following names
have currently been registered: <tt class="docutils literal"><span class="pre">'posix'</span></tt>, <tt class="docutils literal"><span class="pre">'nt'</span></tt>, <tt class="docutils literal"><span class="pre">'mac'</span></tt>, <tt class="docutils literal"><span class="pre">'os2'</span></tt>,
<tt class="docutils literal"><span class="pre">'ce'</span></tt>, <tt class="docutils literal"><span class="pre">'java'</span></tt>, <tt class="docutils literal"><span class="pre">'riscos'</span></tt>.</dd></dl>

<div class="section" id="process-parameters">
<span id="os-procinfo"></span><h2>16.1.1. Process Parameters<a class="headerlink" href="#process-parameters" title="Permalink to this headline">¶</a></h2>
<p>These functions and data items provide information and operate on the current
process and user.</p>
<dl class="data">
<dt id="os.environ">
<tt class="descclassname">os.</tt><tt class="descname">environ</tt><a class="headerlink" href="#os.environ" title="Permalink to this definition">¶</a></dt>
<dd><p>A mapping object representing the string environment. For example,
<tt class="docutils literal"><span class="pre">environ['HOME']</span></tt> is the pathname of your home directory (on some platforms),
and is equivalent to <tt class="docutils literal"><span class="pre">getenv(&quot;HOME&quot;)</span></tt> in C.</p>
<p>This mapping is captured the first time the <tt class="xref docutils literal"><span class="pre">os</span></tt> module is imported,
typically during Python startup as part of processing <tt class="docutils literal"><span class="pre">site.py</span></tt>.  Changes
to the environment made after this time are not reflected in <tt class="docutils literal"><span class="pre">os.environ</span></tt>,
except for changes made by modifying <tt class="docutils literal"><span class="pre">os.environ</span></tt> directly.</p>
<p>If the platform supports the <a title="os.putenv" class="reference internal" href="#os.putenv"><tt class="xref docutils literal"><span class="pre">putenv()</span></tt></a> function, this mapping may be used
to modify the environment as well as query the environment.  <a title="os.putenv" class="reference internal" href="#os.putenv"><tt class="xref docutils literal"><span class="pre">putenv()</span></tt></a> will
be called automatically when the mapping is modified.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Calling <a title="os.putenv" class="reference internal" href="#os.putenv"><tt class="xref docutils literal"><span class="pre">putenv()</span></tt></a> directly does not change <tt class="docutils literal"><span class="pre">os.environ</span></tt>, so it&#8217;s better
to modify <tt class="docutils literal"><span class="pre">os.environ</span></tt>.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">On some platforms, including FreeBSD and Mac OS X, setting <tt class="docutils literal"><span class="pre">environ</span></tt> may
cause memory leaks.  Refer to the system documentation for
<tt class="xref docutils literal"><span class="pre">putenv</span></tt>.</p>
</div>
<p>If <a title="os.putenv" class="reference internal" href="#os.putenv"><tt class="xref docutils literal"><span class="pre">putenv()</span></tt></a> is not provided, a modified copy of this mapping  may be
passed to the appropriate process-creation functions to cause  child processes
to use a modified environment.</p>
<p>If the platform supports the <a title="os.unsetenv" class="reference internal" href="#os.unsetenv"><tt class="xref docutils literal"><span class="pre">unsetenv()</span></tt></a> function, you can delete items in
this mapping to unset environment variables. <a title="os.unsetenv" class="reference internal" href="#os.unsetenv"><tt class="xref docutils literal"><span class="pre">unsetenv()</span></tt></a> will be called
automatically when an item is deleted from <tt class="docutils literal"><span class="pre">os.environ</span></tt>, and when
one of the <tt class="xref docutils literal"><span class="pre">pop()</span></tt> or <tt class="xref docutils literal"><span class="pre">clear()</span></tt> methods is called.</p>
<p>
<span class="versionmodified">Changed in version 2.6: </span>Also unset environment variables when calling <tt class="xref docutils literal"><span class="pre">os.environ.clear()</span></tt>
and <tt class="xref docutils literal"><span class="pre">os.environ.pop()</span></tt>.</p>
</dd></dl>

<dl class="function">
<dt>
<tt class="descclassname">os.</tt><tt class="descname">chdir</tt><big>(</big><em>path</em><big>)</big></dt>
<dt>
<tt class="descclassname">os.</tt><tt class="descname">fchdir</tt><big>(</big><em>fd</em><big>)</big></dt>
<dt>
<tt class="descclassname">os.</tt><tt class="descname">getcwd</tt><big>(</big><big>)</big></dt>
<dd>These functions are described in <a class="reference internal" href="#os-file-dir"><em>Files and Directories</em></a>.</dd></dl>

<dl class="function">
<dt id="os.ctermid">
<tt class="descclassname">os.</tt><tt class="descname">ctermid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.ctermid" title="Permalink to this definition">¶</a></dt>
<dd>Return the filename corresponding to the controlling terminal of the process.
Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.getegid">
<tt class="descclassname">os.</tt><tt class="descname">getegid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getegid" title="Permalink to this definition">¶</a></dt>
<dd>Return the effective group id of the current process.  This corresponds to the
&#8220;set id&#8221; bit on the file being executed in the current process. Availability:
Unix.</dd></dl>

<dl class="function">
<dt id="os.geteuid">
<tt class="descclassname">os.</tt><tt class="descname">geteuid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.geteuid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-425">Return the current process&#8217;s effective user id. Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getgid">
<tt class="descclassname">os.</tt><tt class="descname">getgid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getgid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-426">Return the real group id of the current process. Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getgroups">
<tt class="descclassname">os.</tt><tt class="descname">getgroups</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getgroups" title="Permalink to this definition">¶</a></dt>
<dd>Return list of supplemental group ids associated with the current process.
Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.getlogin">
<tt class="descclassname">os.</tt><tt class="descname">getlogin</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getlogin" title="Permalink to this definition">¶</a></dt>
<dd>Return the name of the user logged in on the controlling terminal of the
process.  For most purposes, it is more useful to use the environment variable
<span class="target" id="index-427"></span><strong class="xref">LOGNAME</strong> to find out who the user is, or
<tt class="docutils literal"><span class="pre">pwd.getpwuid(os.getuid())[0]</span></tt> to get the login name of the currently
effective user id. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.getpgid">
<tt class="descclassname">os.</tt><tt class="descname">getpgid</tt><big>(</big><em>pid</em><big>)</big><a class="headerlink" href="#os.getpgid" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the process group id of the process with process id <em>pid</em>. If <em>pid</em> is 0,
the process group id of the current process is returned. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.getpgrp">
<tt class="descclassname">os.</tt><tt class="descname">getpgrp</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getpgrp" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-428">Return the id of the current process group. Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getpid">
<tt class="descclassname">os.</tt><tt class="descname">getpid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getpid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-429">Return the current process id. Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.getppid">
<tt class="descclassname">os.</tt><tt class="descname">getppid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getppid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-430">Return the parent&#8217;s process id. Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getuid">
<tt class="descclassname">os.</tt><tt class="descname">getuid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getuid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-431">Return the current process&#8217;s user id. Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.getenv">
<tt class="descclassname">os.</tt><tt class="descname">getenv</tt><big>(</big><em>varname</em><span class="optional">[</span>, <em>value</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.getenv" title="Permalink to this definition">¶</a></dt>
<dd>Return the value of the environment variable <em>varname</em> if it exists, or <em>value</em>
if it doesn&#8217;t.  <em>value</em> defaults to <tt class="xref docutils literal"><span class="pre">None</span></tt>. Availability: most flavors of
Unix, Windows.</dd></dl>

<dl class="function">
<dt id="os.putenv">
<tt class="descclassname">os.</tt><tt class="descname">putenv</tt><big>(</big><em>varname</em>, <em>value</em><big>)</big><a class="headerlink" href="#os.putenv" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-432">Set the environment variable named <em>varname</em> to the string <em>value</em>.  Such
changes to the environment affect subprocesses started with <a title="os.system" class="reference internal" href="#os.system"><tt class="xref docutils literal"><span class="pre">os.system()</span></tt></a>,
<a title="os.popen" class="reference internal" href="#os.popen"><tt class="xref docutils literal"><span class="pre">popen()</span></tt></a> or <a title="os.fork" class="reference internal" href="#os.fork"><tt class="xref docutils literal"><span class="pre">fork()</span></tt></a> and <a title="os.execv" class="reference internal" href="#os.execv"><tt class="xref docutils literal"><span class="pre">execv()</span></tt></a>. Availability: most flavors of
Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">On some platforms, including FreeBSD and Mac OS X, setting <tt class="docutils literal"><span class="pre">environ</span></tt> may
cause memory leaks. Refer to the system documentation for putenv.</p>
</div>
<p>When <a title="os.putenv" class="reference internal" href="#os.putenv"><tt class="xref docutils literal"><span class="pre">putenv()</span></tt></a> is supported, assignments to items in <tt class="docutils literal"><span class="pre">os.environ</span></tt> are
automatically translated into corresponding calls to <a title="os.putenv" class="reference internal" href="#os.putenv"><tt class="xref docutils literal"><span class="pre">putenv()</span></tt></a>; however,
calls to <a title="os.putenv" class="reference internal" href="#os.putenv"><tt class="xref docutils literal"><span class="pre">putenv()</span></tt></a> don&#8217;t update <tt class="docutils literal"><span class="pre">os.environ</span></tt>, so it is actually
preferable to assign to items of <tt class="docutils literal"><span class="pre">os.environ</span></tt>.</p>
</dd></dl>

<dl class="function">
<dt id="os.setegid">
<tt class="descclassname">os.</tt><tt class="descname">setegid</tt><big>(</big><em>egid</em><big>)</big><a class="headerlink" href="#os.setegid" title="Permalink to this definition">¶</a></dt>
<dd>Set the current process&#8217;s effective group id. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.seteuid">
<tt class="descclassname">os.</tt><tt class="descname">seteuid</tt><big>(</big><em>euid</em><big>)</big><a class="headerlink" href="#os.seteuid" title="Permalink to this definition">¶</a></dt>
<dd>Set the current process&#8217;s effective user id. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.setgid">
<tt class="descclassname">os.</tt><tt class="descname">setgid</tt><big>(</big><em>gid</em><big>)</big><a class="headerlink" href="#os.setgid" title="Permalink to this definition">¶</a></dt>
<dd>Set the current process&#8217; group id. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.setgroups">
<tt class="descclassname">os.</tt><tt class="descname">setgroups</tt><big>(</big><em>groups</em><big>)</big><a class="headerlink" href="#os.setgroups" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the list of supplemental group ids associated with the current process to
<em>groups</em>. <em>groups</em> must be a sequence, and each element must be an integer
identifying a group. This operation is typically available only to the superuser.
Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.setpgrp">
<tt class="descclassname">os.</tt><tt class="descname">setpgrp</tt><big>(</big><big>)</big><a class="headerlink" href="#os.setpgrp" title="Permalink to this definition">¶</a></dt>
<dd>Call the system call <tt class="xref docutils literal"><span class="pre">setpgrp</span></tt> or <tt class="xref docutils literal"><span class="pre">setpgrp(0,</span> <span class="pre">0)</span></tt> depending on
which version is implemented (if any).  See the Unix manual for the semantics.
Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.setpgid">
<tt class="descclassname">os.</tt><tt class="descname">setpgid</tt><big>(</big><em>pid</em>, <em>pgrp</em><big>)</big><a class="headerlink" href="#os.setpgid" title="Permalink to this definition">¶</a></dt>
<dd>Call the system call <tt class="xref docutils literal"><span class="pre">setpgid</span></tt> to set the process group id of the
process with id <em>pid</em> to the process group with id <em>pgrp</em>.  See the Unix manual
for the semantics. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.setreuid">
<tt class="descclassname">os.</tt><tt class="descname">setreuid</tt><big>(</big><em>ruid</em>, <em>euid</em><big>)</big><a class="headerlink" href="#os.setreuid" title="Permalink to this definition">¶</a></dt>
<dd>Set the current process&#8217;s real and effective user ids. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.setregid">
<tt class="descclassname">os.</tt><tt class="descname">setregid</tt><big>(</big><em>rgid</em>, <em>egid</em><big>)</big><a class="headerlink" href="#os.setregid" title="Permalink to this definition">¶</a></dt>
<dd>Set the current process&#8217;s real and effective group ids. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.getsid">
<tt class="descclassname">os.</tt><tt class="descname">getsid</tt><big>(</big><em>pid</em><big>)</big><a class="headerlink" href="#os.getsid" title="Permalink to this definition">¶</a></dt>
<dd><p>Call the system call <tt class="xref docutils literal"><span class="pre">getsid</span></tt>.  See the Unix manual for the semantics.
Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.4.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.setsid">
<tt class="descclassname">os.</tt><tt class="descname">setsid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.setsid" title="Permalink to this definition">¶</a></dt>
<dd>Call the system call <tt class="xref docutils literal"><span class="pre">setsid</span></tt>.  See the Unix manual for the semantics.
Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.setuid">
<tt class="descclassname">os.</tt><tt class="descname">setuid</tt><big>(</big><em>uid</em><big>)</big><a class="headerlink" href="#os.setuid" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-433">Set the current process&#8217;s user id. Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.strerror">
<tt class="descclassname">os.</tt><tt class="descname">strerror</tt><big>(</big><em>code</em><big>)</big><a class="headerlink" href="#os.strerror" title="Permalink to this definition">¶</a></dt>
<dd>Return the error message corresponding to the error code in <em>code</em>.
On platforms where <tt class="xref docutils literal"><span class="pre">strerror</span></tt> returns <tt class="docutils literal"><span class="pre">NULL</span></tt> when given an unknown
error number, <a title="exceptions.ValueError" class="reference external" href="exceptions.html#exceptions.ValueError"><tt class="xref docutils literal"><span class="pre">ValueError</span></tt></a> is raised.  Availability: Unix, Windows.</dd></dl>

<dl class="function">
<dt id="os.umask">
<tt class="descclassname">os.</tt><tt class="descname">umask</tt><big>(</big><em>mask</em><big>)</big><a class="headerlink" href="#os.umask" title="Permalink to this definition">¶</a></dt>
<dd>Set the current numeric umask and return the previous umask. Availability:
Unix, Windows.</dd></dl>

<dl class="function">
<dt id="os.uname">
<tt class="descclassname">os.</tt><tt class="descname">uname</tt><big>(</big><big>)</big><a class="headerlink" href="#os.uname" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-434">Return a 5-tuple containing information identifying the current operating
system.  The tuple contains 5 strings: <tt class="docutils literal"><span class="pre">(sysname,</span> <span class="pre">nodename,</span> <span class="pre">release,</span> <span class="pre">version,</span>
<span class="pre">machine)</span></tt>.  Some systems truncate the nodename to 8 characters or to the
leading component; a better way to get the hostname is
<a title="socket.gethostname" class="reference external" href="socket.html#socket.gethostname"><tt class="xref docutils literal"><span class="pre">socket.gethostname()</span></tt></a>  or even
<tt class="docutils literal"><span class="pre">socket.gethostbyaddr(socket.gethostname())</span></tt>. Availability: recent flavors of
Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.unsetenv">
<tt class="descclassname">os.</tt><tt class="descname">unsetenv</tt><big>(</big><em>varname</em><big>)</big><a class="headerlink" href="#os.unsetenv" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-435">Unset (delete) the environment variable named <em>varname</em>. Such changes to the
environment affect subprocesses started with <a title="os.system" class="reference internal" href="#os.system"><tt class="xref docutils literal"><span class="pre">os.system()</span></tt></a>, <a title="os.popen" class="reference internal" href="#os.popen"><tt class="xref docutils literal"><span class="pre">popen()</span></tt></a> or
<a title="os.fork" class="reference internal" href="#os.fork"><tt class="xref docutils literal"><span class="pre">fork()</span></tt></a> and <a title="os.execv" class="reference internal" href="#os.execv"><tt class="xref docutils literal"><span class="pre">execv()</span></tt></a>. Availability: most flavors of Unix, Windows.</p>
<p>When <a title="os.unsetenv" class="reference internal" href="#os.unsetenv"><tt class="xref docutils literal"><span class="pre">unsetenv()</span></tt></a> is supported, deletion of items in <tt class="docutils literal"><span class="pre">os.environ</span></tt> is
automatically translated into a corresponding call to <a title="os.unsetenv" class="reference internal" href="#os.unsetenv"><tt class="xref docutils literal"><span class="pre">unsetenv()</span></tt></a>; however,
calls to <a title="os.unsetenv" class="reference internal" href="#os.unsetenv"><tt class="xref docutils literal"><span class="pre">unsetenv()</span></tt></a> don&#8217;t update <tt class="docutils literal"><span class="pre">os.environ</span></tt>, so it is actually
preferable to delete items of <tt class="docutils literal"><span class="pre">os.environ</span></tt>.</p>
</dd></dl>

</div>
<div class="section" id="file-object-creation">
<span id="os-newstreams"></span><h2>16.1.2. File Object Creation<a class="headerlink" href="#file-object-creation" title="Permalink to this headline">¶</a></h2>
<p>These functions create new file objects. (See also <a title="open" class="reference external" href="functions.html#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a>.)</p>
<dl class="function">
<dt id="os.fdopen">
<tt class="descclassname">os.</tt><tt class="descname">fdopen</tt><big>(</big><em>fd</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.fdopen" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-436">Return an open file object connected to the file descriptor <em>fd</em>.  The <em>mode</em>
and <em>bufsize</em> arguments have the same meaning as the corresponding arguments to
the built-in <a title="open" class="reference external" href="functions.html#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a> function. Availability: Unix, Windows.</p>
<p>
<span class="versionmodified">Changed in version 2.3: </span>When specified, the <em>mode</em> argument must now start with one of the letters
<tt class="docutils literal"><span class="pre">'r'</span></tt>, <tt class="docutils literal"><span class="pre">'w'</span></tt>, or <tt class="docutils literal"><span class="pre">'a'</span></tt>, otherwise a <a title="exceptions.ValueError" class="reference external" href="exceptions.html#exceptions.ValueError"><tt class="xref docutils literal"><span class="pre">ValueError</span></tt></a> is raised.</p>
<p>
<span class="versionmodified">Changed in version 2.5: </span>On Unix, when the <em>mode</em> argument starts with <tt class="docutils literal"><span class="pre">'a'</span></tt>, the <em>O_APPEND</em> flag is
set on the file descriptor (which the <tt class="xref docutils literal"><span class="pre">fdopen</span></tt> implementation already
does on most platforms).</p>
</dd></dl>

<dl class="function">
<dt id="os.popen">
<tt class="descclassname">os.</tt><tt class="descname">popen</tt><big>(</big><em>command</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.popen" title="Permalink to this definition">¶</a></dt>
<dd><p>Open a pipe to or from <em>command</em>.  The return value is an open file object
connected to the pipe, which can be read or written depending on whether <em>mode</em>
is <tt class="docutils literal"><span class="pre">'r'</span></tt> (default) or <tt class="docutils literal"><span class="pre">'w'</span></tt>. The <em>bufsize</em> argument has the same meaning as
the corresponding argument to the built-in <a title="open" class="reference external" href="functions.html#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a> function.  The exit
status of the command (encoded in the format specified for <a title="os.wait" class="reference internal" href="#os.wait"><tt class="xref docutils literal"><span class="pre">wait()</span></tt></a>) is
available as the return value of the <a title="os.close" class="reference internal" href="#os.close"><tt class="xref docutils literal"><span class="pre">close()</span></tt></a> method of the file object,
except that when the exit status is zero (termination without errors), <tt class="xref docutils literal"><span class="pre">None</span></tt>
is returned. Availability: Unix, Windows.</p>
<p>
<span class="versionmodified">Deprecated since version 2.6: </span>This function is obsolete.  Use the <a title="Subprocess management." class="reference external" href="subprocess.html#module-subprocess"><tt class="xref docutils literal"><span class="pre">subprocess</span></tt></a> module.  Check
especially the <a class="reference external" href="subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section.</p>
<p>
<span class="versionmodified">Changed in version 2.0: </span>This function worked unreliably under Windows in earlier versions of Python.
This was due to the use of the <tt class="xref docutils literal"><span class="pre">_popen</span></tt> function from the libraries
provided with Windows.  Newer versions of Python do not use the broken
implementation from the Windows libraries.</p>
</dd></dl>

<dl class="function">
<dt id="os.tmpfile">
<tt class="descclassname">os.</tt><tt class="descname">tmpfile</tt><big>(</big><big>)</big><a class="headerlink" href="#os.tmpfile" title="Permalink to this definition">¶</a></dt>
<dd>Return a new file object opened in update mode (<tt class="docutils literal"><span class="pre">w+b</span></tt>).  The file has no
directory entries associated with it and will be automatically deleted once
there are no file descriptors for the file. Availability: Unix,
Windows.</dd></dl>

<p>There are a number of different <tt class="xref docutils literal"><span class="pre">popen*()</span></tt> functions that provide slightly
different ways to create subprocesses.</p>
<p>
<span class="versionmodified">Deprecated since version 2.6: </span>All of the <tt class="xref docutils literal"><span class="pre">popen*()</span></tt> functions are obsolete. Use the <a title="Subprocess management." class="reference external" href="subprocess.html#module-subprocess"><tt class="xref docutils literal"><span class="pre">subprocess</span></tt></a>
module.</p>
<p>For each of the <tt class="xref docutils literal"><span class="pre">popen*()</span></tt> variants, if <em>bufsize</em> is specified, it
specifies the buffer size for the I/O pipes. <em>mode</em>, if provided, should be the
string <tt class="docutils literal"><span class="pre">'b'</span></tt> or <tt class="docutils literal"><span class="pre">'t'</span></tt>; on Windows this is needed to determine whether the
file objects should be opened in binary or text mode.  The default value for
<em>mode</em> is <tt class="docutils literal"><span class="pre">'t'</span></tt>.</p>
<p>Also, for each of these variants, on Unix, <em>cmd</em> may be a sequence, in which
case arguments will be passed directly to the program without shell intervention
(as with <a title="os.spawnv" class="reference internal" href="#os.spawnv"><tt class="xref docutils literal"><span class="pre">os.spawnv()</span></tt></a>). If <em>cmd</em> is a string it will be passed to the shell
(as with <a title="os.system" class="reference internal" href="#os.system"><tt class="xref docutils literal"><span class="pre">os.system()</span></tt></a>).</p>
<p>These methods do not make it possible to retrieve the exit status from the child
processes.  The only way to control the input and output streams and also
retrieve the return codes is to use the <a title="Subprocess management." class="reference external" href="subprocess.html#module-subprocess"><tt class="xref docutils literal"><span class="pre">subprocess</span></tt></a> module; these are only
available on Unix.</p>
<p>For a discussion of possible deadlock conditions related to the use of these
functions, see <a class="reference external" href="popen2.html#popen2-flow-control"><em>Flow Control Issues</em></a>.</p>
<dl class="function">
<dt id="os.popen2">
<tt class="descclassname">os.</tt><tt class="descname">popen2</tt><big>(</big><em>cmd</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.popen2" title="Permalink to this definition">¶</a></dt>
<dd><p>Execute <em>cmd</em> as a sub-process and return the file objects <tt class="docutils literal"><span class="pre">(child_stdin,</span>
<span class="pre">child_stdout)</span></tt>.</p>
<p>
<span class="versionmodified">Deprecated since version 2.6: </span>This function is obsolete.  Use the <a title="Subprocess management." class="reference external" href="subprocess.html#module-subprocess"><tt class="xref docutils literal"><span class="pre">subprocess</span></tt></a> module.  Check
especially the <a class="reference external" href="subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section.</p>
<p>Availability: Unix, Windows.</p>
<p>
<span class="versionmodified">New in version 2.0.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.popen3">
<tt class="descclassname">os.</tt><tt class="descname">popen3</tt><big>(</big><em>cmd</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.popen3" title="Permalink to this definition">¶</a></dt>
<dd><p>Execute <em>cmd</em> as a sub-process and return the file objects <tt class="docutils literal"><span class="pre">(child_stdin,</span>
<span class="pre">child_stdout,</span> <span class="pre">child_stderr)</span></tt>.</p>
<p>
<span class="versionmodified">Deprecated since version 2.6: </span>This function is obsolete.  Use the <a title="Subprocess management." class="reference external" href="subprocess.html#module-subprocess"><tt class="xref docutils literal"><span class="pre">subprocess</span></tt></a> module.  Check
especially the <a class="reference external" href="subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section.</p>
<p>Availability: Unix, Windows.</p>
<p>
<span class="versionmodified">New in version 2.0.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.popen4">
<tt class="descclassname">os.</tt><tt class="descname">popen4</tt><big>(</big><em>cmd</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.popen4" title="Permalink to this definition">¶</a></dt>
<dd><p>Execute <em>cmd</em> as a sub-process and return the file objects <tt class="docutils literal"><span class="pre">(child_stdin,</span>
<span class="pre">child_stdout_and_stderr)</span></tt>.</p>
<p>
<span class="versionmodified">Deprecated since version 2.6: </span>This function is obsolete.  Use the <a title="Subprocess management." class="reference external" href="subprocess.html#module-subprocess"><tt class="xref docutils literal"><span class="pre">subprocess</span></tt></a> module.  Check
especially the <a class="reference external" href="subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section.</p>
<p>Availability: Unix, Windows.</p>
<p>
<span class="versionmodified">New in version 2.0.</span></p>
</dd></dl>

<p>(Note that <tt class="docutils literal"><span class="pre">child_stdin,</span> <span class="pre">child_stdout,</span> <span class="pre">and</span> <span class="pre">child_stderr</span></tt> are named from the
point of view of the child process, so <em>child_stdin</em> is the child&#8217;s standard
input.)</p>
<p>This functionality is also available in the <a title="Subprocesses with accessible standard I/O streams. (deprecated)" class="reference external" href="popen2.html#module-popen2"><tt class="xref docutils literal"><span class="pre">popen2</span></tt></a> module using functions
of the same names, but the return values of those functions have a different
order.</p>
</div>
<div class="section" id="file-descriptor-operations">
<span id="os-fd-ops"></span><h2>16.1.3. File Descriptor Operations<a class="headerlink" href="#file-descriptor-operations" title="Permalink to this headline">¶</a></h2>
<p>These functions operate on I/O streams referenced using file descriptors.</p>
<p>File descriptors are small integers corresponding to a file that has been opened
by the current process.  For example, standard input is usually file descriptor
0, standard output is 1, and standard error is 2.  Further files opened by a
process will then be assigned 3, 4, 5, and so forth.  The name &#8220;file descriptor&#8221;
is slightly deceptive; on Unix platforms, sockets and pipes are also referenced
by file descriptors.</p>
<dl class="function">
<dt id="os.close">
<tt class="descclassname">os.</tt><tt class="descname">close</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.close" title="Permalink to this definition">¶</a></dt>
<dd><p>Close file descriptor <em>fd</em>. Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is intended for low-level I/O and must be applied to a file
descriptor as returned by <a title="open" class="reference external" href="functions.html#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a> or <a title="os.pipe" class="reference internal" href="#os.pipe"><tt class="xref docutils literal"><span class="pre">pipe()</span></tt></a>.  To close a &#8220;file
object&#8221; returned by the built-in function <a title="open" class="reference external" href="functions.html#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a> or by <a title="os.popen" class="reference internal" href="#os.popen"><tt class="xref docutils literal"><span class="pre">popen()</span></tt></a> or
<a title="os.fdopen" class="reference internal" href="#os.fdopen"><tt class="xref docutils literal"><span class="pre">fdopen()</span></tt></a>, use its <a title="os.close" class="reference internal" href="#os.close"><tt class="xref docutils literal"><span class="pre">close()</span></tt></a> method.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.closerange">
<tt class="descclassname">os.</tt><tt class="descname">closerange</tt><big>(</big><em>fd_low</em>, <em>fd_high</em><big>)</big><a class="headerlink" href="#os.closerange" title="Permalink to this definition">¶</a></dt>
<dd><p>Close all file descriptors from <em>fd_low</em> (inclusive) to <em>fd_high</em> (exclusive),
ignoring errors. Availability: Unix, Windows. Equivalent to:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">for</span> <span class="n">fd</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">fd_low</span><span class="p">,</span> <span class="n">fd_high</span><span class="p">):</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">os</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="n">fd</span><span class="p">)</span>
    <span class="k">except</span> <span class="ne">OSError</span><span class="p">:</span>
        <span class="k">pass</span>
</pre></div>
</div>
<p>
<span class="versionmodified">New in version 2.6.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.dup">
<tt class="descclassname">os.</tt><tt class="descname">dup</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.dup" title="Permalink to this definition">¶</a></dt>
<dd>Return a duplicate of file descriptor <em>fd</em>. Availability: Unix,
Windows.</dd></dl>

<dl class="function">
<dt id="os.dup2">
<tt class="descclassname">os.</tt><tt class="descname">dup2</tt><big>(</big><em>fd</em>, <em>fd2</em><big>)</big><a class="headerlink" href="#os.dup2" title="Permalink to this definition">¶</a></dt>
<dd>Duplicate file descriptor <em>fd</em> to <em>fd2</em>, closing the latter first if necessary.
Availability: Unix, Windows.</dd></dl>

<dl class="function">
<dt id="os.fchmod">
<tt class="descclassname">os.</tt><tt class="descname">fchmod</tt><big>(</big><em>fd</em>, <em>mode</em><big>)</big><a class="headerlink" href="#os.fchmod" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the mode of the file given by <em>fd</em> to the numeric <em>mode</em>.  See the docs
for <a title="os.chmod" class="reference internal" href="#os.chmod"><tt class="xref docutils literal"><span class="pre">chmod()</span></tt></a> for possible values of <em>mode</em>.  Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.6.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.fchown">
<tt class="descclassname">os.</tt><tt class="descname">fchown</tt><big>(</big><em>fd</em>, <em>uid</em>, <em>gid</em><big>)</big><a class="headerlink" href="#os.fchown" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the owner and group id of the file given by <em>fd</em> to the numeric <em>uid</em>
and <em>gid</em>.  To leave one of the ids unchanged, set it to -1.
Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.6.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.fdatasync">
<tt class="descclassname">os.</tt><tt class="descname">fdatasync</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fdatasync" title="Permalink to this definition">¶</a></dt>
<dd>Force write of file with filedescriptor <em>fd</em> to disk. Does not force update of
metadata. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.fpathconf">
<tt class="descclassname">os.</tt><tt class="descname">fpathconf</tt><big>(</big><em>fd</em>, <em>name</em><big>)</big><a class="headerlink" href="#os.fpathconf" title="Permalink to this definition">¶</a></dt>
<dd><p>Return system configuration information relevant to an open file. <em>name</em>
specifies the configuration value to retrieve; it may be a string which is the
name of a defined system value; these names are specified in a number of
standards (POSIX.1, Unix 95, Unix 98, and others).  Some platforms define
additional names as well.  The names known to the host operating system are
given in the <tt class="docutils literal"><span class="pre">pathconf_names</span></tt> dictionary.  For configuration variables not
included in that mapping, passing an integer for <em>name</em> is also accepted.
Availability: Unix.</p>
<p>If <em>name</em> is a string and is not known, <a title="exceptions.ValueError" class="reference external" href="exceptions.html#exceptions.ValueError"><tt class="xref docutils literal"><span class="pre">ValueError</span></tt></a> is raised.  If a
specific value for <em>name</em> is not supported by the host system, even if it is
included in <tt class="docutils literal"><span class="pre">pathconf_names</span></tt>, an <a title="exceptions.OSError" class="reference external" href="exceptions.html#exceptions.OSError"><tt class="xref docutils literal"><span class="pre">OSError</span></tt></a> is raised with
<a title="errno.EINVAL" class="reference external" href="errno.html#errno.EINVAL"><tt class="xref docutils literal"><span class="pre">errno.EINVAL</span></tt></a> for the error number.</p>
</dd></dl>

<dl class="function">
<dt id="os.fstat">
<tt class="descclassname">os.</tt><tt class="descname">fstat</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fstat" title="Permalink to this definition">¶</a></dt>
<dd>Return status for file descriptor <em>fd</em>, like <a title="os.stat" class="reference internal" href="#os.stat"><tt class="xref docutils literal"><span class="pre">stat()</span></tt></a>. Availability:
Unix, Windows.</dd></dl>

<dl class="function">
<dt id="os.fstatvfs">
<tt class="descclassname">os.</tt><tt class="descname">fstatvfs</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fstatvfs" title="Permalink to this definition">¶</a></dt>
<dd>Return information about the filesystem containing the file associated with file
descriptor <em>fd</em>, like <a title="os.statvfs" class="reference internal" href="#os.statvfs"><tt class="xref docutils literal"><span class="pre">statvfs()</span></tt></a>. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.fsync">
<tt class="descclassname">os.</tt><tt class="descname">fsync</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fsync" title="Permalink to this definition">¶</a></dt>
<dd><p>Force write of file with filedescriptor <em>fd</em> to disk.  On Unix, this calls the
native <tt class="xref docutils literal"><span class="pre">fsync</span></tt> function; on Windows, the MS <tt class="xref docutils literal"><span class="pre">_commit</span></tt> function.</p>
<p>If you&#8217;re starting with a Python file object <em>f</em>, first do <tt class="docutils literal"><span class="pre">f.flush()</span></tt>, and
then do <tt class="docutils literal"><span class="pre">os.fsync(f.fileno())</span></tt>, to ensure that all internal buffers associated
with <em>f</em> are written to disk. Availability: Unix, and Windows
starting in 2.2.3.</p>
</dd></dl>

<dl class="function">
<dt id="os.ftruncate">
<tt class="descclassname">os.</tt><tt class="descname">ftruncate</tt><big>(</big><em>fd</em>, <em>length</em><big>)</big><a class="headerlink" href="#os.ftruncate" title="Permalink to this definition">¶</a></dt>
<dd>Truncate the file corresponding to file descriptor <em>fd</em>, so that it is at most
<em>length</em> bytes in size. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.isatty">
<tt class="descclassname">os.</tt><tt class="descname">isatty</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.isatty" title="Permalink to this definition">¶</a></dt>
<dd>Return <tt class="xref docutils literal"><span class="pre">True</span></tt> if the file descriptor <em>fd</em> is open and connected to a
tty(-like) device, else <tt class="xref docutils literal"><span class="pre">False</span></tt>. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.lseek">
<tt class="descclassname">os.</tt><tt class="descname">lseek</tt><big>(</big><em>fd</em>, <em>pos</em>, <em>how</em><big>)</big><a class="headerlink" href="#os.lseek" title="Permalink to this definition">¶</a></dt>
<dd>Set the current position of file descriptor <em>fd</em> to position <em>pos</em>, modified
by <em>how</em>: <a title="os.SEEK_SET" class="reference internal" href="#os.SEEK_SET"><tt class="xref docutils literal"><span class="pre">SEEK_SET</span></tt></a> or <tt class="docutils literal"><span class="pre">0</span></tt> to set the position relative to the
beginning of the file; <a title="os.SEEK_CUR" class="reference internal" href="#os.SEEK_CUR"><tt class="xref docutils literal"><span class="pre">SEEK_CUR</span></tt></a> or <tt class="docutils literal"><span class="pre">1</span></tt> to set it relative to the
current position; <a title="os.SEEK_END" class="reference internal" href="#os.SEEK_END"><tt class="xref docutils literal"><span class="pre">os.SEEK_END</span></tt></a> or <tt class="docutils literal"><span class="pre">2</span></tt> to set it relative to the end of
the file. Availability: Unix, Windows.</dd></dl>

<dl class="function">
<dt id="os.open">
<tt class="descclassname">os.</tt><tt class="descname">open</tt><big>(</big><em>file</em>, <em>flags</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.open" title="Permalink to this definition">¶</a></dt>
<dd><p>Open the file <em>file</em> and set various flags according to <em>flags</em> and possibly its
mode according to <em>mode</em>. The default <em>mode</em> is <tt class="docutils literal"><span class="pre">0777</span></tt> (octal), and the
current umask value is first masked out.  Return the file descriptor for the
newly opened file. Availability: Unix, Windows.</p>
<p>For a description of the flag and mode values, see the C run-time documentation;
flag constants (like <a title="os.O_RDONLY" class="reference internal" href="#os.O_RDONLY"><tt class="xref docutils literal"><span class="pre">O_RDONLY</span></tt></a> and <a title="os.O_WRONLY" class="reference internal" href="#os.O_WRONLY"><tt class="xref docutils literal"><span class="pre">O_WRONLY</span></tt></a>) are defined in
this module too (see below).</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is intended for low-level I/O.  For normal usage, use the built-in
function <a title="open" class="reference external" href="functions.html#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a>, which returns a &#8220;file object&#8221; with <a title="os.read" class="reference internal" href="#os.read"><tt class="xref docutils literal"><span class="pre">read()</span></tt></a> and
<a title="os.write" class="reference internal" href="#os.write"><tt class="xref docutils literal"><span class="pre">write()</span></tt></a> methods (and many more).  To wrap a file descriptor in a &#8220;file
object&#8221;, use <a title="os.fdopen" class="reference internal" href="#os.fdopen"><tt class="xref docutils literal"><span class="pre">fdopen()</span></tt></a>.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.openpty">
<tt class="descclassname">os.</tt><tt class="descname">openpty</tt><big>(</big><big>)</big><a class="headerlink" href="#os.openpty" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-437">Open a new pseudo-terminal pair. Return a pair of file descriptors <tt class="docutils literal"><span class="pre">(master,</span>
<span class="pre">slave)</span></tt> for the pty and the tty, respectively. For a (slightly) more portable
approach, use the <a title="(IRIX, Linux) Pseudo-Terminal Handling for SGI and Linux." class="reference external" href="pty.html#module-pty"><tt class="xref docutils literal"><span class="pre">pty</span></tt></a> module. Availability: some flavors of
Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.pipe">
<tt class="descclassname">os.</tt><tt class="descname">pipe</tt><big>(</big><big>)</big><a class="headerlink" href="#os.pipe" title="Permalink to this definition">¶</a></dt>
<dd>Create a pipe.  Return a pair of file descriptors <tt class="docutils literal"><span class="pre">(r,</span> <span class="pre">w)</span></tt> usable for reading
and writing, respectively. Availability: Unix, Windows.</dd></dl>

<dl class="function">
<dt id="os.read">
<tt class="descclassname">os.</tt><tt class="descname">read</tt><big>(</big><em>fd</em>, <em>n</em><big>)</big><a class="headerlink" href="#os.read" title="Permalink to this definition">¶</a></dt>
<dd><p>Read at most <em>n</em> bytes from file descriptor <em>fd</em>. Return a string containing the
bytes read.  If the end of the file referred to by <em>fd</em> has been reached, an
empty string is returned. Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is intended for low-level I/O and must be applied to a file
descriptor as returned by <a title="open" class="reference external" href="functions.html#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a> or <a title="os.pipe" class="reference internal" href="#os.pipe"><tt class="xref docutils literal"><span class="pre">pipe()</span></tt></a>.  To read a &#8220;file object&#8221;
returned by the built-in function <a title="open" class="reference external" href="functions.html#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a> or by <a title="os.popen" class="reference internal" href="#os.popen"><tt class="xref docutils literal"><span class="pre">popen()</span></tt></a> or
<a title="os.fdopen" class="reference internal" href="#os.fdopen"><tt class="xref docutils literal"><span class="pre">fdopen()</span></tt></a>, or <a title="sys.stdin" class="reference external" href="sys.html#sys.stdin"><tt class="xref docutils literal"><span class="pre">sys.stdin</span></tt></a>, use its <a title="os.read" class="reference internal" href="#os.read"><tt class="xref docutils literal"><span class="pre">read()</span></tt></a> or <tt class="xref docutils literal"><span class="pre">readline()</span></tt>
methods.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.tcgetpgrp">
<tt class="descclassname">os.</tt><tt class="descname">tcgetpgrp</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.tcgetpgrp" title="Permalink to this definition">¶</a></dt>
<dd>Return the process group associated with the terminal given by <em>fd</em> (an open
file descriptor as returned by <a title="open" class="reference external" href="functions.html#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a>). Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.tcsetpgrp">
<tt class="descclassname">os.</tt><tt class="descname">tcsetpgrp</tt><big>(</big><em>fd</em>, <em>pg</em><big>)</big><a class="headerlink" href="#os.tcsetpgrp" title="Permalink to this definition">¶</a></dt>
<dd>Set the process group associated with the terminal given by <em>fd</em> (an open file
descriptor as returned by <a title="open" class="reference external" href="functions.html#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a>) to <em>pg</em>. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.ttyname">
<tt class="descclassname">os.</tt><tt class="descname">ttyname</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.ttyname" title="Permalink to this definition">¶</a></dt>
<dd>Return a string which specifies the terminal device associated with
file descriptor <em>fd</em>.  If <em>fd</em> is not associated with a terminal device, an
exception is raised. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.write">
<tt class="descclassname">os.</tt><tt class="descname">write</tt><big>(</big><em>fd</em>, <em>str</em><big>)</big><a class="headerlink" href="#os.write" title="Permalink to this definition">¶</a></dt>
<dd><p>Write the string <em>str</em> to file descriptor <em>fd</em>. Return the number of bytes
actually written. Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function is intended for low-level I/O and must be applied to a file
descriptor as returned by <a title="open" class="reference external" href="functions.html#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a> or <a title="os.pipe" class="reference internal" href="#os.pipe"><tt class="xref docutils literal"><span class="pre">pipe()</span></tt></a>.  To write a &#8220;file
object&#8221; returned by the built-in function <a title="open" class="reference external" href="functions.html#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a> or by <a title="os.popen" class="reference internal" href="#os.popen"><tt class="xref docutils literal"><span class="pre">popen()</span></tt></a> or
<a title="os.fdopen" class="reference internal" href="#os.fdopen"><tt class="xref docutils literal"><span class="pre">fdopen()</span></tt></a>, or <a title="sys.stdout" class="reference external" href="sys.html#sys.stdout"><tt class="xref docutils literal"><span class="pre">sys.stdout</span></tt></a> or <a title="sys.stderr" class="reference external" href="sys.html#sys.stderr"><tt class="xref docutils literal"><span class="pre">sys.stderr</span></tt></a>, use its <a title="os.write" class="reference internal" href="#os.write"><tt class="xref docutils literal"><span class="pre">write()</span></tt></a>
method.</p>
</div>
</dd></dl>

<p>The following constants are options for the <em>flags</em> parameter to the
<a title="open" class="reference external" href="functions.html#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a> function.  They can be combined using the bitwise OR operator
<tt class="docutils literal"><span class="pre">|</span></tt>.  Some of them are not available on all platforms.  For descriptions of
their availability and use, consult the <em>open(2)</em> manual page on Unix
or <cite>the MSDN &lt;http://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx&gt;</cite> on Windows.</p>
<dl class="data">
<dt id="os.O_RDONLY">
<tt class="descclassname">os.</tt><tt class="descname">O_RDONLY</tt><a class="headerlink" href="#os.O_RDONLY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_WRONLY">
<tt class="descclassname">os.</tt><tt class="descname">O_WRONLY</tt><a class="headerlink" href="#os.O_WRONLY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_RDWR">
<tt class="descclassname">os.</tt><tt class="descname">O_RDWR</tt><a class="headerlink" href="#os.O_RDWR" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_APPEND">
<tt class="descclassname">os.</tt><tt class="descname">O_APPEND</tt><a class="headerlink" href="#os.O_APPEND" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_CREAT">
<tt class="descclassname">os.</tt><tt class="descname">O_CREAT</tt><a class="headerlink" href="#os.O_CREAT" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_EXCL">
<tt class="descclassname">os.</tt><tt class="descname">O_EXCL</tt><a class="headerlink" href="#os.O_EXCL" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_TRUNC">
<tt class="descclassname">os.</tt><tt class="descname">O_TRUNC</tt><a class="headerlink" href="#os.O_TRUNC" title="Permalink to this definition">¶</a></dt>
<dd>These constants are available on Unix and Windows.</dd></dl>

<dl class="data">
<dt id="os.O_DSYNC">
<tt class="descclassname">os.</tt><tt class="descname">O_DSYNC</tt><a class="headerlink" href="#os.O_DSYNC" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_RSYNC">
<tt class="descclassname">os.</tt><tt class="descname">O_RSYNC</tt><a class="headerlink" href="#os.O_RSYNC" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_SYNC">
<tt class="descclassname">os.</tt><tt class="descname">O_SYNC</tt><a class="headerlink" href="#os.O_SYNC" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NDELAY">
<tt class="descclassname">os.</tt><tt class="descname">O_NDELAY</tt><a class="headerlink" href="#os.O_NDELAY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NONBLOCK">
<tt class="descclassname">os.</tt><tt class="descname">O_NONBLOCK</tt><a class="headerlink" href="#os.O_NONBLOCK" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NOCTTY">
<tt class="descclassname">os.</tt><tt class="descname">O_NOCTTY</tt><a class="headerlink" href="#os.O_NOCTTY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_SHLOCK">
<tt class="descclassname">os.</tt><tt class="descname">O_SHLOCK</tt><a class="headerlink" href="#os.O_SHLOCK" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_EXLOCK">
<tt class="descclassname">os.</tt><tt class="descname">O_EXLOCK</tt><a class="headerlink" href="#os.O_EXLOCK" title="Permalink to this definition">¶</a></dt>
<dd>These constants are only available on Unix.</dd></dl>

<dl class="data">
<dt id="os.O_BINARY">
<tt class="descclassname">os.</tt><tt class="descname">O_BINARY</tt><a class="headerlink" href="#os.O_BINARY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NOINHERIT">
<tt class="descclassname">os.</tt><tt class="descname">O_NOINHERIT</tt><a class="headerlink" href="#os.O_NOINHERIT" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_SHORT_LIVED">
<tt class="descclassname">os.</tt><tt class="descname">O_SHORT_LIVED</tt><a class="headerlink" href="#os.O_SHORT_LIVED" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_TEMPORARY">
<tt class="descclassname">os.</tt><tt class="descname">O_TEMPORARY</tt><a class="headerlink" href="#os.O_TEMPORARY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_RANDOM">
<tt class="descclassname">os.</tt><tt class="descname">O_RANDOM</tt><a class="headerlink" href="#os.O_RANDOM" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_SEQUENTIAL">
<tt class="descclassname">os.</tt><tt class="descname">O_SEQUENTIAL</tt><a class="headerlink" href="#os.O_SEQUENTIAL" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_TEXT">
<tt class="descclassname">os.</tt><tt class="descname">O_TEXT</tt><a class="headerlink" href="#os.O_TEXT" title="Permalink to this definition">¶</a></dt>
<dd>These constants are only available on Windows.</dd></dl>

<dl class="data">
<dt id="os.O_ASYNC">
<tt class="descclassname">os.</tt><tt class="descname">O_ASYNC</tt><a class="headerlink" href="#os.O_ASYNC" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_DIRECT">
<tt class="descclassname">os.</tt><tt class="descname">O_DIRECT</tt><a class="headerlink" href="#os.O_DIRECT" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_DIRECTORY">
<tt class="descclassname">os.</tt><tt class="descname">O_DIRECTORY</tt><a class="headerlink" href="#os.O_DIRECTORY" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NOFOLLOW">
<tt class="descclassname">os.</tt><tt class="descname">O_NOFOLLOW</tt><a class="headerlink" href="#os.O_NOFOLLOW" title="Permalink to this definition">¶</a></dt>
<dt id="os.O_NOATIME">
<tt class="descclassname">os.</tt><tt class="descname">O_NOATIME</tt><a class="headerlink" href="#os.O_NOATIME" title="Permalink to this definition">¶</a></dt>
<dd>These constants are GNU extensions and not present if they are not defined by
the C library.</dd></dl>

<dl class="data">
<dt id="os.SEEK_SET">
<tt class="descclassname">os.</tt><tt class="descname">SEEK_SET</tt><a class="headerlink" href="#os.SEEK_SET" title="Permalink to this definition">¶</a></dt>
<dt id="os.SEEK_CUR">
<tt class="descclassname">os.</tt><tt class="descname">SEEK_CUR</tt><a class="headerlink" href="#os.SEEK_CUR" title="Permalink to this definition">¶</a></dt>
<dt id="os.SEEK_END">
<tt class="descclassname">os.</tt><tt class="descname">SEEK_END</tt><a class="headerlink" href="#os.SEEK_END" title="Permalink to this definition">¶</a></dt>
<dd><p>Parameters to the <a title="os.lseek" class="reference internal" href="#os.lseek"><tt class="xref docutils literal"><span class="pre">lseek()</span></tt></a> function. Their values are 0, 1, and 2,
respectively. Availability: Windows, Unix.</p>
<p>
<span class="versionmodified">New in version 2.5.</span></p>
</dd></dl>

</div>
<div class="section" id="files-and-directories">
<span id="os-file-dir"></span><h2>16.1.4. Files and Directories<a class="headerlink" href="#files-and-directories" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="os.access">
<tt class="descclassname">os.</tt><tt class="descname">access</tt><big>(</big><em>path</em>, <em>mode</em><big>)</big><a class="headerlink" href="#os.access" title="Permalink to this definition">¶</a></dt>
<dd><p>Use the real uid/gid to test for access to <em>path</em>.  Note that most operations
will use the effective uid/gid, therefore this routine can be used in a
suid/sgid environment to test if the invoking user has the specified access to
<em>path</em>.  <em>mode</em> should be <a title="os.F_OK" class="reference internal" href="#os.F_OK"><tt class="xref docutils literal"><span class="pre">F_OK</span></tt></a> to test the existence of <em>path</em>, or it
can be the inclusive OR of one or more of <a title="os.R_OK" class="reference internal" href="#os.R_OK"><tt class="xref docutils literal"><span class="pre">R_OK</span></tt></a>, <a title="os.W_OK" class="reference internal" href="#os.W_OK"><tt class="xref docutils literal"><span class="pre">W_OK</span></tt></a>, and
<a title="os.X_OK" class="reference internal" href="#os.X_OK"><tt class="xref docutils literal"><span class="pre">X_OK</span></tt></a> to test permissions.  Return <a title="True" class="reference external" href="constants.html#True"><tt class="xref xref docutils literal"><span class="pre">True</span></tt></a> if access is allowed,
<a title="False" class="reference external" href="constants.html#False"><tt class="xref xref docutils literal"><span class="pre">False</span></tt></a> if not. See the Unix man page <em>access(2)</em> for more
information. Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Using <a title="os.access" class="reference internal" href="#os.access"><tt class="xref docutils literal"><span class="pre">access()</span></tt></a> to check if a user is authorized to e.g. open a file before
actually doing so using <a title="open" class="reference external" href="functions.html#open"><tt class="xref docutils literal"><span class="pre">open()</span></tt></a> creates a  security hole, because the user
might exploit the short time interval  between checking and opening the file to
manipulate it.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">I/O operations may fail even when <a title="os.access" class="reference internal" href="#os.access"><tt class="xref docutils literal"><span class="pre">access()</span></tt></a> indicates that they would
succeed, particularly for operations on network filesystems which may have
permissions semantics beyond the usual POSIX permission-bit model.</p>
</div>
</dd></dl>

<dl class="data">
<dt id="os.F_OK">
<tt class="descclassname">os.</tt><tt class="descname">F_OK</tt><a class="headerlink" href="#os.F_OK" title="Permalink to this definition">¶</a></dt>
<dd>Value to pass as the <em>mode</em> parameter of <a title="os.access" class="reference internal" href="#os.access"><tt class="xref docutils literal"><span class="pre">access()</span></tt></a> to test the existence of
<em>path</em>.</dd></dl>

<dl class="data">
<dt id="os.R_OK">
<tt class="descclassname">os.</tt><tt class="descname">R_OK</tt><a class="headerlink" href="#os.R_OK" title="Permalink to this definition">¶</a></dt>
<dd>Value to include in the <em>mode</em> parameter of <a title="os.access" class="reference internal" href="#os.access"><tt class="xref docutils literal"><span class="pre">access()</span></tt></a> to test the
readability of <em>path</em>.</dd></dl>

<dl class="data">
<dt id="os.W_OK">
<tt class="descclassname">os.</tt><tt class="descname">W_OK</tt><a class="headerlink" href="#os.W_OK" title="Permalink to this definition">¶</a></dt>
<dd>Value to include in the <em>mode</em> parameter of <a title="os.access" class="reference internal" href="#os.access"><tt class="xref docutils literal"><span class="pre">access()</span></tt></a> to test the
writability of <em>path</em>.</dd></dl>

<dl class="data">
<dt id="os.X_OK">
<tt class="descclassname">os.</tt><tt class="descname">X_OK</tt><a class="headerlink" href="#os.X_OK" title="Permalink to this definition">¶</a></dt>
<dd>Value to include in the <em>mode</em> parameter of <a title="os.access" class="reference internal" href="#os.access"><tt class="xref docutils literal"><span class="pre">access()</span></tt></a> to determine if
<em>path</em> can be executed.</dd></dl>

<dl class="function">
<dt id="os.chdir">
<tt class="descclassname">os.</tt><tt class="descname">chdir</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.chdir" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-438">Change the current working directory to <em>path</em>. Availability: Unix,
Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.fchdir">
<tt class="descclassname">os.</tt><tt class="descname">fchdir</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fchdir" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the current working directory to the directory represented by the file
descriptor <em>fd</em>.  The descriptor must refer to an opened directory, not an open
file. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.getcwd">
<tt class="descclassname">os.</tt><tt class="descname">getcwd</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getcwd" title="Permalink to this definition">¶</a></dt>
<dd>Return a string representing the current working directory. Availability:
Unix, Windows.</dd></dl>

<dl class="function">
<dt id="os.getcwdu">
<tt class="descclassname">os.</tt><tt class="descname">getcwdu</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getcwdu" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a Unicode object representing the current working directory.
Availability: Unix, Windows.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.chflags">
<tt class="descclassname">os.</tt><tt class="descname">chflags</tt><big>(</big><em>path</em>, <em>flags</em><big>)</big><a class="headerlink" href="#os.chflags" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the flags of <em>path</em> to the numeric <em>flags</em>. <em>flags</em> may take a combination
(bitwise OR) of the following values (as defined in the <a title="Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()." class="reference external" href="stat.html#module-stat"><tt class="xref docutils literal"><span class="pre">stat</span></tt></a> module):</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">UF_NODUMP</span></tt></li>
<li><tt class="docutils literal"><span class="pre">UF_IMMUTABLE</span></tt></li>
<li><tt class="docutils literal"><span class="pre">UF_APPEND</span></tt></li>
<li><tt class="docutils literal"><span class="pre">UF_OPAQUE</span></tt></li>
<li><tt class="docutils literal"><span class="pre">UF_NOUNLINK</span></tt></li>
<li><tt class="docutils literal"><span class="pre">SF_ARCHIVED</span></tt></li>
<li><tt class="docutils literal"><span class="pre">SF_IMMUTABLE</span></tt></li>
<li><tt class="docutils literal"><span class="pre">SF_APPEND</span></tt></li>
<li><tt class="docutils literal"><span class="pre">SF_NOUNLINK</span></tt></li>
<li><tt class="docutils literal"><span class="pre">SF_SNAPSHOT</span></tt></li>
</ul>
<p>Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.6.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.chroot">
<tt class="descclassname">os.</tt><tt class="descname">chroot</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.chroot" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the root directory of the current process to <em>path</em>. Availability:
Unix.</p>
<p>
<span class="versionmodified">New in version 2.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.chmod">
<tt class="descclassname">os.</tt><tt class="descname">chmod</tt><big>(</big><em>path</em>, <em>mode</em><big>)</big><a class="headerlink" href="#os.chmod" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the mode of <em>path</em> to the numeric <em>mode</em>. <em>mode</em> may take one of the
following values (as defined in the <a title="Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()." class="reference external" href="stat.html#module-stat"><tt class="xref docutils literal"><span class="pre">stat</span></tt></a> module) or bitwise ORed
combinations of them:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">stat.S_ISUID</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_ISGID</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_ENFMT</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_ISVTX</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_IREAD</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_IWRITE</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_IEXEC</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_IRWXU</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_IRUSR</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_IWUSR</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_IXUSR</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_IRWXG</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_IRGRP</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_IWGRP</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_IXGRP</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_IRWXO</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_IROTH</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_IWOTH</span></tt></li>
<li><tt class="docutils literal"><span class="pre">stat.S_IXOTH</span></tt></li>
</ul>
<p>Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Although Windows supports <a title="os.chmod" class="reference internal" href="#os.chmod"><tt class="xref docutils literal"><span class="pre">chmod()</span></tt></a>, you can only  set the file&#8217;s read-only
flag with it (via the <tt class="docutils literal"><span class="pre">stat.S_IWRITE</span></tt>  and <tt class="docutils literal"><span class="pre">stat.S_IREAD</span></tt>
constants or a corresponding integer value).  All other bits are
ignored.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.chown">
<tt class="descclassname">os.</tt><tt class="descname">chown</tt><big>(</big><em>path</em>, <em>uid</em>, <em>gid</em><big>)</big><a class="headerlink" href="#os.chown" title="Permalink to this definition">¶</a></dt>
<dd>Change the owner and group id of <em>path</em> to the numeric <em>uid</em> and <em>gid</em>. To leave
one of the ids unchanged, set it to -1. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.lchflags">
<tt class="descclassname">os.</tt><tt class="descname">lchflags</tt><big>(</big><em>path</em>, <em>flags</em><big>)</big><a class="headerlink" href="#os.lchflags" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the flags of <em>path</em> to the numeric <em>flags</em>, like <a title="os.chflags" class="reference internal" href="#os.chflags"><tt class="xref docutils literal"><span class="pre">chflags()</span></tt></a>, but do not
follow symbolic links. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.6.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.lchmod">
<tt class="descclassname">os.</tt><tt class="descname">lchmod</tt><big>(</big><em>path</em>, <em>mode</em><big>)</big><a class="headerlink" href="#os.lchmod" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the mode of <em>path</em> to the numeric <em>mode</em>. If path is a symlink, this
affects the symlink rather than the target. See the docs for <a title="os.chmod" class="reference internal" href="#os.chmod"><tt class="xref docutils literal"><span class="pre">chmod()</span></tt></a>
for possible values of <em>mode</em>.  Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.6.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.lchown">
<tt class="descclassname">os.</tt><tt class="descname">lchown</tt><big>(</big><em>path</em>, <em>uid</em>, <em>gid</em><big>)</big><a class="headerlink" href="#os.lchown" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the owner and group id of <em>path</em> to the numeric <em>uid</em> and <em>gid</em>. This
function will not follow symbolic links. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.link">
<tt class="descclassname">os.</tt><tt class="descname">link</tt><big>(</big><em>src</em>, <em>dst</em><big>)</big><a class="headerlink" href="#os.link" title="Permalink to this definition">¶</a></dt>
<dd>Create a hard link pointing to <em>src</em> named <em>dst</em>. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.listdir">
<tt class="descclassname">os.</tt><tt class="descname">listdir</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.listdir" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list containing the names of the entries in the directory given by
<em>path</em>.  The list is in arbitrary order.  It does not include the special
entries <tt class="docutils literal"><span class="pre">'.'</span></tt> and <tt class="docutils literal"><span class="pre">'..'</span></tt> even if they are present in the
directory.  Availability: Unix, Windows.</p>
<p>
<span class="versionmodified">Changed in version 2.3: </span>On Windows NT/2k/XP and Unix, if <em>path</em> is a Unicode object, the result will be
a list of Unicode objects.</p>
</dd></dl>

<dl class="function">
<dt id="os.lstat">
<tt class="descclassname">os.</tt><tt class="descname">lstat</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.lstat" title="Permalink to this definition">¶</a></dt>
<dd>Like <a title="os.stat" class="reference internal" href="#os.stat"><tt class="xref docutils literal"><span class="pre">stat()</span></tt></a>, but do not follow symbolic links.  This is an alias for
<a title="os.stat" class="reference internal" href="#os.stat"><tt class="xref docutils literal"><span class="pre">stat()</span></tt></a> on platforms that do not support symbolic links, such as
Windows.</dd></dl>

<dl class="function">
<dt id="os.mkfifo">
<tt class="descclassname">os.</tt><tt class="descname">mkfifo</tt><big>(</big><em>path</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.mkfifo" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a FIFO (a named pipe) named <em>path</em> with numeric mode <em>mode</em>.  The default
<em>mode</em> is <tt class="docutils literal"><span class="pre">0666</span></tt> (octal).  The current umask value is first masked out from
the mode. Availability: Unix.</p>
<p>FIFOs are pipes that can be accessed like regular files.  FIFOs exist until they
are deleted (for example with <a title="os.unlink" class="reference internal" href="#os.unlink"><tt class="xref docutils literal"><span class="pre">os.unlink()</span></tt></a>). Generally, FIFOs are used as
rendezvous between &#8220;client&#8221; and &#8220;server&#8221; type processes: the server opens the
FIFO for reading, and the client opens it for writing.  Note that <a title="os.mkfifo" class="reference internal" href="#os.mkfifo"><tt class="xref docutils literal"><span class="pre">mkfifo()</span></tt></a>
doesn&#8217;t open the FIFO &#8212; it just creates the rendezvous point.</p>
</dd></dl>

<dl class="function">
<dt id="os.mknod">
<tt class="descclassname">os.</tt><tt class="descname">mknod</tt><big>(</big><em>filename</em><span class="optional">[</span>, <em>mode=0600</em>, <em>device</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.mknod" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a filesystem node (file, device special file or named pipe) named
<em>filename</em>. <em>mode</em> specifies both the permissions to use and the type of node to
be created, being combined (bitwise OR) with one of <tt class="docutils literal"><span class="pre">stat.S_IFREG</span></tt>,
<tt class="docutils literal"><span class="pre">stat.S_IFCHR</span></tt>, <tt class="docutils literal"><span class="pre">stat.S_IFBLK</span></tt>,
and <tt class="docutils literal"><span class="pre">stat.S_IFIFO</span></tt> (those constants are available in <a title="Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()." class="reference external" href="stat.html#module-stat"><tt class="xref docutils literal"><span class="pre">stat</span></tt></a>).
For <tt class="docutils literal"><span class="pre">stat.S_IFCHR</span></tt> and
<tt class="docutils literal"><span class="pre">stat.S_IFBLK</span></tt>, <em>device</em> defines the newly created device special file (probably using
<a title="os.makedev" class="reference internal" href="#os.makedev"><tt class="xref docutils literal"><span class="pre">os.makedev()</span></tt></a>), otherwise it is ignored.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.major">
<tt class="descclassname">os.</tt><tt class="descname">major</tt><big>(</big><em>device</em><big>)</big><a class="headerlink" href="#os.major" title="Permalink to this definition">¶</a></dt>
<dd><p>Extract the device major number from a raw device number (usually the
<tt class="xref docutils literal"><span class="pre">st_dev</span></tt> or <tt class="xref docutils literal"><span class="pre">st_rdev</span></tt> field from <tt class="xref docutils literal"><span class="pre">stat</span></tt>).</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.minor">
<tt class="descclassname">os.</tt><tt class="descname">minor</tt><big>(</big><em>device</em><big>)</big><a class="headerlink" href="#os.minor" title="Permalink to this definition">¶</a></dt>
<dd><p>Extract the device minor number from a raw device number (usually the
<tt class="xref docutils literal"><span class="pre">st_dev</span></tt> or <tt class="xref docutils literal"><span class="pre">st_rdev</span></tt> field from <tt class="xref docutils literal"><span class="pre">stat</span></tt>).</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.makedev">
<tt class="descclassname">os.</tt><tt class="descname">makedev</tt><big>(</big><em>major</em>, <em>minor</em><big>)</big><a class="headerlink" href="#os.makedev" title="Permalink to this definition">¶</a></dt>
<dd><p>Compose a raw device number from the major and minor device numbers.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.mkdir">
<tt class="descclassname">os.</tt><tt class="descname">mkdir</tt><big>(</big><em>path</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.mkdir" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a directory named <em>path</em> with numeric mode <em>mode</em>. The default <em>mode</em> is
<tt class="docutils literal"><span class="pre">0777</span></tt> (octal).  On some systems, <em>mode</em> is ignored.  Where it is used, the
current umask value is first masked out. Availability: Unix, Windows.</p>
<p>It is also possible to create temporary directories; see the
<a title="Generate temporary files and directories." class="reference external" href="tempfile.html#module-tempfile"><tt class="xref docutils literal"><span class="pre">tempfile</span></tt></a> module&#8217;s <a title="tempfile.mkdtemp" class="reference external" href="tempfile.html#tempfile.mkdtemp"><tt class="xref docutils literal"><span class="pre">tempfile.mkdtemp()</span></tt></a> function.</p>
</dd></dl>

<dl class="function">
<dt id="os.makedirs">
<tt class="descclassname">os.</tt><tt class="descname">makedirs</tt><big>(</big><em>path</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.makedirs" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-439">Recursive directory creation function.  Like <a title="os.mkdir" class="reference internal" href="#os.mkdir"><tt class="xref docutils literal"><span class="pre">mkdir()</span></tt></a>, but makes all
intermediate-level directories needed to contain the leaf directory.  Throws an
<a title="os.error" class="reference internal" href="#os.error"><tt class="xref docutils literal"><span class="pre">error</span></tt></a> exception if the leaf directory already exists or cannot be
created.  The default <em>mode</em> is <tt class="docutils literal"><span class="pre">0777</span></tt> (octal).  On some systems, <em>mode</em> is
ignored. Where it is used, the current umask value is first masked out.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><a title="os.makedirs" class="reference internal" href="#os.makedirs"><tt class="xref docutils literal"><span class="pre">makedirs()</span></tt></a> will become confused if the path elements to create include
<a title="os.pardir" class="reference internal" href="#os.pardir"><tt class="xref docutils literal"><span class="pre">os.pardir</span></tt></a>.</p>
</div>
<p>
<span class="versionmodified">New in version 1.5.2.</span></p>
<p>
<span class="versionmodified">Changed in version 2.3: </span>This function now handles UNC paths correctly.</p>
</dd></dl>

<dl class="function">
<dt id="os.pathconf">
<tt class="descclassname">os.</tt><tt class="descname">pathconf</tt><big>(</big><em>path</em>, <em>name</em><big>)</big><a class="headerlink" href="#os.pathconf" title="Permalink to this definition">¶</a></dt>
<dd><p>Return system configuration information relevant to a named file. <em>name</em>
specifies the configuration value to retrieve; it may be a string which is the
name of a defined system value; these names are specified in a number of
standards (POSIX.1, Unix 95, Unix 98, and others).  Some platforms define
additional names as well.  The names known to the host operating system are
given in the <tt class="docutils literal"><span class="pre">pathconf_names</span></tt> dictionary.  For configuration variables not
included in that mapping, passing an integer for <em>name</em> is also accepted.
Availability: Unix.</p>
<p>If <em>name</em> is a string and is not known, <a title="exceptions.ValueError" class="reference external" href="exceptions.html#exceptions.ValueError"><tt class="xref docutils literal"><span class="pre">ValueError</span></tt></a> is raised.  If a
specific value for <em>name</em> is not supported by the host system, even if it is
included in <tt class="docutils literal"><span class="pre">pathconf_names</span></tt>, an <a title="exceptions.OSError" class="reference external" href="exceptions.html#exceptions.OSError"><tt class="xref docutils literal"><span class="pre">OSError</span></tt></a> is raised with
<a title="errno.EINVAL" class="reference external" href="errno.html#errno.EINVAL"><tt class="xref docutils literal"><span class="pre">errno.EINVAL</span></tt></a> for the error number.</p>
</dd></dl>

<dl class="data">
<dt id="os.pathconf_names">
<tt class="descclassname">os.</tt><tt class="descname">pathconf_names</tt><a class="headerlink" href="#os.pathconf_names" title="Permalink to this definition">¶</a></dt>
<dd>Dictionary mapping names accepted by <a title="os.pathconf" class="reference internal" href="#os.pathconf"><tt class="xref docutils literal"><span class="pre">pathconf()</span></tt></a> and <a title="os.fpathconf" class="reference internal" href="#os.fpathconf"><tt class="xref docutils literal"><span class="pre">fpathconf()</span></tt></a> to
the integer values defined for those names by the host operating system.  This
can be used to determine the set of names known to the system. Availability:
Unix.</dd></dl>

<dl class="function">
<dt id="os.readlink">
<tt class="descclassname">os.</tt><tt class="descname">readlink</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.readlink" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string representing the path to which the symbolic link points.  The
result may be either an absolute or relative pathname; if it is relative, it may
be converted to an absolute pathname using <tt class="docutils literal"><span class="pre">os.path.join(os.path.dirname(path),</span>
<span class="pre">result)</span></tt>.</p>
<p>
<span class="versionmodified">Changed in version 2.6: </span>If the <em>path</em> is a Unicode object the result will also be a Unicode object.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.remove">
<tt class="descclassname">os.</tt><tt class="descname">remove</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.remove" title="Permalink to this definition">¶</a></dt>
<dd>Remove the file <em>path</em>.  If <em>path</em> is a directory, <a title="exceptions.OSError" class="reference external" href="exceptions.html#exceptions.OSError"><tt class="xref docutils literal"><span class="pre">OSError</span></tt></a> is raised; see
<a title="os.rmdir" class="reference internal" href="#os.rmdir"><tt class="xref docutils literal"><span class="pre">rmdir()</span></tt></a> below to remove a directory.  This is identical to the
<a title="os.unlink" class="reference internal" href="#os.unlink"><tt class="xref docutils literal"><span class="pre">unlink()</span></tt></a> function documented below.  On Windows, attempting to remove a
file that is in use causes an exception to be raised; on Unix, the directory
entry is removed but the storage allocated to the file is not made available
until the original file is no longer in use. Availability: Unix,
Windows.</dd></dl>

<dl class="function">
<dt id="os.removedirs">
<tt class="descclassname">os.</tt><tt class="descname">removedirs</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.removedirs" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-440">Remove directories recursively.  Works like <a title="os.rmdir" class="reference internal" href="#os.rmdir"><tt class="xref docutils literal"><span class="pre">rmdir()</span></tt></a> except that, if the
leaf directory is successfully removed, <a title="os.removedirs" class="reference internal" href="#os.removedirs"><tt class="xref docutils literal"><span class="pre">removedirs()</span></tt></a>  tries to
successively remove every parent directory mentioned in  <em>path</em> until an error
is raised (which is ignored, because it generally means that a parent directory
is not empty). For example, <tt class="docutils literal"><span class="pre">os.removedirs('foo/bar/baz')</span></tt> will first remove
the directory <tt class="docutils literal"><span class="pre">'foo/bar/baz'</span></tt>, and then remove <tt class="docutils literal"><span class="pre">'foo/bar'</span></tt> and <tt class="docutils literal"><span class="pre">'foo'</span></tt> if
they are empty. Raises <a title="exceptions.OSError" class="reference external" href="exceptions.html#exceptions.OSError"><tt class="xref docutils literal"><span class="pre">OSError</span></tt></a> if the leaf directory could not be
successfully removed.</p>
<p>
<span class="versionmodified">New in version 1.5.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.rename">
<tt class="descclassname">os.</tt><tt class="descname">rename</tt><big>(</big><em>src</em>, <em>dst</em><big>)</big><a class="headerlink" href="#os.rename" title="Permalink to this definition">¶</a></dt>
<dd>Rename the file or directory <em>src</em> to <em>dst</em>.  If <em>dst</em> is a directory,
<a title="exceptions.OSError" class="reference external" href="exceptions.html#exceptions.OSError"><tt class="xref docutils literal"><span class="pre">OSError</span></tt></a> will be raised.  On Unix, if <em>dst</em> exists and is a file, it will
be replaced silently if the user has permission.  The operation may fail on some
Unix flavors if <em>src</em> and <em>dst</em> are on different filesystems.  If successful,
the renaming will be an atomic operation (this is a POSIX requirement).  On
Windows, if <em>dst</em> already exists, <a title="exceptions.OSError" class="reference external" href="exceptions.html#exceptions.OSError"><tt class="xref docutils literal"><span class="pre">OSError</span></tt></a> will be raised even if it is a
file; there may be no way to implement an atomic rename when <em>dst</em> names an
existing file. Availability: Unix, Windows.</dd></dl>

<dl class="function">
<dt id="os.renames">
<tt class="descclassname">os.</tt><tt class="descname">renames</tt><big>(</big><em>old</em>, <em>new</em><big>)</big><a class="headerlink" href="#os.renames" title="Permalink to this definition">¶</a></dt>
<dd><p>Recursive directory or file renaming function. Works like <a title="os.rename" class="reference internal" href="#os.rename"><tt class="xref docutils literal"><span class="pre">rename()</span></tt></a>, except
creation of any intermediate directories needed to make the new pathname good is
attempted first. After the rename, directories corresponding to rightmost path
segments of the old name will be pruned away using <a title="os.removedirs" class="reference internal" href="#os.removedirs"><tt class="xref docutils literal"><span class="pre">removedirs()</span></tt></a>.</p>
<p>
<span class="versionmodified">New in version 1.5.2.</span></p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function can fail with the new directory structure made if you lack
permissions needed to remove the leaf directory or file.</p>
</div>
</dd></dl>

<dl class="function">
<dt id="os.rmdir">
<tt class="descclassname">os.</tt><tt class="descname">rmdir</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.rmdir" title="Permalink to this definition">¶</a></dt>
<dd>Remove the directory <em>path</em>. Availability: Unix, Windows.</dd></dl>

<dl class="function">
<dt id="os.stat">
<tt class="descclassname">os.</tt><tt class="descname">stat</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.stat" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform a <tt class="xref docutils literal"><span class="pre">stat</span></tt> system call on the given path.  The return value is an
object whose attributes correspond to the members of the <tt class="xref docutils literal"><span class="pre">stat</span></tt>
structure, namely: <tt class="xref docutils literal"><span class="pre">st_mode</span></tt> (protection bits), <tt class="xref docutils literal"><span class="pre">st_ino</span></tt> (inode
number), <tt class="xref docutils literal"><span class="pre">st_dev</span></tt> (device), <tt class="xref docutils literal"><span class="pre">st_nlink</span></tt> (number of hard links),
<tt class="xref docutils literal"><span class="pre">st_uid</span></tt> (user id of owner), <tt class="xref docutils literal"><span class="pre">st_gid</span></tt> (group id of owner),
<tt class="xref docutils literal"><span class="pre">st_size</span></tt> (size of file, in bytes), <tt class="xref docutils literal"><span class="pre">st_atime</span></tt> (time of most recent
access), <tt class="xref docutils literal"><span class="pre">st_mtime</span></tt> (time of most recent content modification),
<tt class="xref docutils literal"><span class="pre">st_ctime</span></tt> (platform dependent; time of most recent metadata change on
Unix, or the time of creation on Windows):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">os</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">statinfo</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="s">&#39;somefile.txt&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">statinfo</span>
<span class="go">(33188, 422511L, 769L, 1, 1032, 100, 926L, 1105022698,1105022732, 1105022732)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">statinfo</span><span class="o">.</span><span class="n">st_size</span>
<span class="go">926L</span>
<span class="go">&gt;&gt;&gt;</span>
</pre></div>
</div>
<p>
<span class="versionmodified">Changed in version 2.3: </span>If <a title="os.stat_float_times" class="reference internal" href="#os.stat_float_times"><tt class="xref docutils literal"><span class="pre">stat_float_times()</span></tt></a> returns <tt class="xref docutils literal"><span class="pre">True</span></tt>, the time values are floats, measuring
seconds. Fractions of a second may be reported if the system supports that. On
Mac OS, the times are always floats. See <a title="os.stat_float_times" class="reference internal" href="#os.stat_float_times"><tt class="xref docutils literal"><span class="pre">stat_float_times()</span></tt></a> for further
discussion.</p>
<p>On some Unix systems (such as Linux), the following attributes may also be
available: <tt class="xref docutils literal"><span class="pre">st_blocks</span></tt> (number of blocks allocated for file),
<tt class="xref docutils literal"><span class="pre">st_blksize</span></tt> (filesystem blocksize), <tt class="xref docutils literal"><span class="pre">st_rdev</span></tt> (type of device if an
inode device). <tt class="xref docutils literal"><span class="pre">st_flags</span></tt> (user defined flags for file).</p>
<p>On other Unix systems (such as FreeBSD), the following attributes may be
available (but may be only filled out if root tries to use them): <tt class="xref docutils literal"><span class="pre">st_gen</span></tt>
(file generation number), <tt class="xref docutils literal"><span class="pre">st_birthtime</span></tt> (time of file creation).</p>
<p>On Mac OS systems, the following attributes may also be available:
<tt class="xref docutils literal"><span class="pre">st_rsize</span></tt>, <tt class="xref docutils literal"><span class="pre">st_creator</span></tt>, <tt class="xref docutils literal"><span class="pre">st_type</span></tt>.</p>
<p>On RISCOS systems, the following attributes are also available: <tt class="xref docutils literal"><span class="pre">st_ftype</span></tt>
(file type), <tt class="xref docutils literal"><span class="pre">st_attrs</span></tt> (attributes), <tt class="xref docutils literal"><span class="pre">st_obtype</span></tt> (object type).</p>
<p id="index-441">For backward compatibility, the return value of <a title="os.stat" class="reference internal" href="#os.stat"><tt class="xref docutils literal"><span class="pre">stat()</span></tt></a> is also accessible
as a tuple of at least 10 integers giving the most important (and portable)
members of the <tt class="xref docutils literal"><span class="pre">stat</span></tt> structure, in the order <tt class="xref docutils literal"><span class="pre">st_mode</span></tt>,
<tt class="xref docutils literal"><span class="pre">st_ino</span></tt>, <tt class="xref docutils literal"><span class="pre">st_dev</span></tt>, <tt class="xref docutils literal"><span class="pre">st_nlink</span></tt>, <tt class="xref docutils literal"><span class="pre">st_uid</span></tt>,
<tt class="xref docutils literal"><span class="pre">st_gid</span></tt>, <tt class="xref docutils literal"><span class="pre">st_size</span></tt>, <tt class="xref docutils literal"><span class="pre">st_atime</span></tt>, <tt class="xref docutils literal"><span class="pre">st_mtime</span></tt>,
<tt class="xref docutils literal"><span class="pre">st_ctime</span></tt>. More items may be added at the end by some implementations.
The standard module <a title="Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()." class="reference external" href="stat.html#module-stat"><tt class="xref docutils literal"><span class="pre">stat</span></tt></a> defines functions and constants that are useful
for extracting information from a <tt class="xref docutils literal"><span class="pre">stat</span></tt> structure. (On Windows, some
items are filled with dummy values.)</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The exact meaning and resolution of the <tt class="xref docutils literal"><span class="pre">st_atime</span></tt>, <tt class="xref docutils literal"><span class="pre">st_mtime</span></tt>, and
<tt class="xref docutils literal"><span class="pre">st_ctime</span></tt> members depends on the operating system and the file system.
For example, on Windows systems using the FAT or FAT32 file systems,
<tt class="xref docutils literal"><span class="pre">st_mtime</span></tt> has 2-second resolution, and <tt class="xref docutils literal"><span class="pre">st_atime</span></tt> has only 1-day
resolution.  See your operating system documentation for details.</p>
</div>
<p>Availability: Unix, Windows.</p>
<p>
<span class="versionmodified">Changed in version 2.2: </span>Added access to values as attributes of the returned object.</p>
<p>
<span class="versionmodified">Changed in version 2.5: </span>Added <tt class="xref docutils literal"><span class="pre">st_gen</span></tt> and <tt class="xref docutils literal"><span class="pre">st_birthtime</span></tt>.</p>
</dd></dl>

<dl class="function">
<dt id="os.stat_float_times">
<tt class="descclassname">os.</tt><tt class="descname">stat_float_times</tt><big>(</big><span class="optional">[</span><em>newvalue</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.stat_float_times" title="Permalink to this definition">¶</a></dt>
<dd><p>Determine whether <tt class="xref docutils literal"><span class="pre">stat_result</span></tt> represents time stamps as float objects.
If <em>newvalue</em> is <tt class="xref docutils literal"><span class="pre">True</span></tt>, future calls to <a title="os.stat" class="reference internal" href="#os.stat"><tt class="xref docutils literal"><span class="pre">stat()</span></tt></a> return floats, if it is
<tt class="xref docutils literal"><span class="pre">False</span></tt>, future calls return ints. If <em>newvalue</em> is omitted, return the
current setting.</p>
<p>For compatibility with older Python versions, accessing <tt class="xref docutils literal"><span class="pre">stat_result</span></tt> as
a tuple always returns integers.</p>
<p>
<span class="versionmodified">Changed in version 2.5: </span>Python now returns float values by default. Applications which do not work
correctly with floating point time stamps can use this function to restore the
old behaviour.</p>
<p>The resolution of the timestamps (that is the smallest possible fraction)
depends on the system. Some systems only support second resolution; on these
systems, the fraction will always be zero.</p>
<p>It is recommended that this setting is only changed at program startup time in
the <em>__main__</em> module; libraries should never change this setting. If an
application uses a library that works incorrectly if floating point time stamps
are processed, this application should turn the feature off until the library
has been corrected.</p>
</dd></dl>

<dl class="function">
<dt id="os.statvfs">
<tt class="descclassname">os.</tt><tt class="descname">statvfs</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.statvfs" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform a <tt class="xref docutils literal"><span class="pre">statvfs</span></tt> system call on the given path.  The return value is
an object whose attributes describe the filesystem on the given path, and
correspond to the members of the <tt class="xref docutils literal"><span class="pre">statvfs</span></tt> structure, namely:
<tt class="xref docutils literal"><span class="pre">f_bsize</span></tt>, <tt class="xref docutils literal"><span class="pre">f_frsize</span></tt>, <tt class="xref docutils literal"><span class="pre">f_blocks</span></tt>, <tt class="xref docutils literal"><span class="pre">f_bfree</span></tt>,
<tt class="xref docutils literal"><span class="pre">f_bavail</span></tt>, <tt class="xref docutils literal"><span class="pre">f_files</span></tt>, <tt class="xref docutils literal"><span class="pre">f_ffree</span></tt>, <tt class="xref docutils literal"><span class="pre">f_favail</span></tt>,
<tt class="xref docutils literal"><span class="pre">f_flag</span></tt>, <tt class="xref docutils literal"><span class="pre">f_namemax</span></tt>. Availability: Unix.</p>
<p id="index-442">For backward compatibility, the return value is also accessible as a tuple whose
values correspond to the attributes, in the order given above. The standard
module <a title="Constants for interpreting the result of os.statvfs(). (deprecated)" class="reference external" href="statvfs.html#module-statvfs"><tt class="xref docutils literal"><span class="pre">statvfs</span></tt></a> defines constants that are useful for extracting
information from a <tt class="xref docutils literal"><span class="pre">statvfs</span></tt> structure when accessing it as a sequence;
this remains useful when writing code that needs to work with versions of Python
that don&#8217;t support accessing the fields as attributes.</p>
<p>
<span class="versionmodified">Changed in version 2.2: </span>Added access to values as attributes of the returned object.</p>
</dd></dl>

<dl class="function">
<dt id="os.symlink">
<tt class="descclassname">os.</tt><tt class="descname">symlink</tt><big>(</big><em>src</em>, <em>dst</em><big>)</big><a class="headerlink" href="#os.symlink" title="Permalink to this definition">¶</a></dt>
<dd>Create a symbolic link pointing to <em>src</em> named <em>dst</em>. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.tempnam">
<tt class="descclassname">os.</tt><tt class="descname">tempnam</tt><big>(</big><span class="optional">[</span><em>dir</em><span class="optional">[</span>, <em>prefix</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.tempnam" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a unique path name that is reasonable for creating a temporary file.
This will be an absolute path that names a potential directory entry in the
directory <em>dir</em> or a common location for temporary files if <em>dir</em> is omitted or
<tt class="xref docutils literal"><span class="pre">None</span></tt>.  If given and not <tt class="xref docutils literal"><span class="pre">None</span></tt>, <em>prefix</em> is used to provide a short prefix
to the filename.  Applications are responsible for properly creating and
managing files created using paths returned by <a title="os.tempnam" class="reference internal" href="#os.tempnam"><tt class="xref docutils literal"><span class="pre">tempnam()</span></tt></a>; no automatic
cleanup is provided. On Unix, the environment variable <span class="target" id="index-443"></span><strong class="xref">TMPDIR</strong>
overrides <em>dir</em>, while on Windows <span class="target" id="index-444"></span><strong class="xref">TMP</strong> is used.  The specific
behavior of this function depends on the C library implementation; some aspects
are underspecified in system documentation.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">Use of <a title="os.tempnam" class="reference internal" href="#os.tempnam"><tt class="xref docutils literal"><span class="pre">tempnam()</span></tt></a> is vulnerable to symlink attacks; consider using
<a title="os.tmpfile" class="reference internal" href="#os.tmpfile"><tt class="xref docutils literal"><span class="pre">tmpfile()</span></tt></a> (section <a class="reference internal" href="#os-newstreams"><em>File Object Creation</em></a>) instead.</p>
</div>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.tmpnam">
<tt class="descclassname">os.</tt><tt class="descname">tmpnam</tt><big>(</big><big>)</big><a class="headerlink" href="#os.tmpnam" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a unique path name that is reasonable for creating a temporary file.
This will be an absolute path that names a potential directory entry in a common
location for temporary files.  Applications are responsible for properly
creating and managing files created using paths returned by <a title="os.tmpnam" class="reference internal" href="#os.tmpnam"><tt class="xref docutils literal"><span class="pre">tmpnam()</span></tt></a>; no
automatic cleanup is provided.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">Use of <a title="os.tmpnam" class="reference internal" href="#os.tmpnam"><tt class="xref docutils literal"><span class="pre">tmpnam()</span></tt></a> is vulnerable to symlink attacks; consider using
<a title="os.tmpfile" class="reference internal" href="#os.tmpfile"><tt class="xref docutils literal"><span class="pre">tmpfile()</span></tt></a> (section <a class="reference internal" href="#os-newstreams"><em>File Object Creation</em></a>) instead.</p>
</div>
<p>Availability: Unix, Windows.  This function probably shouldn&#8217;t be used on
Windows, though: Microsoft&#8217;s implementation of <a title="os.tmpnam" class="reference internal" href="#os.tmpnam"><tt class="xref docutils literal"><span class="pre">tmpnam()</span></tt></a> always creates a
name in the root directory of the current drive, and that&#8217;s generally a poor
location for a temp file (depending on privileges, you may not even be able to
open a file using this name).</p>
</dd></dl>

<dl class="data">
<dt id="os.TMP_MAX">
<tt class="descclassname">os.</tt><tt class="descname">TMP_MAX</tt><a class="headerlink" href="#os.TMP_MAX" title="Permalink to this definition">¶</a></dt>
<dd>The maximum number of unique names that <a title="os.tmpnam" class="reference internal" href="#os.tmpnam"><tt class="xref docutils literal"><span class="pre">tmpnam()</span></tt></a> will generate before
reusing names.</dd></dl>

<dl class="function">
<dt id="os.unlink">
<tt class="descclassname">os.</tt><tt class="descname">unlink</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.unlink" title="Permalink to this definition">¶</a></dt>
<dd>Remove the file <em>path</em>.  This is the same function as <a title="os.remove" class="reference internal" href="#os.remove"><tt class="xref docutils literal"><span class="pre">remove()</span></tt></a>; the
<a title="os.unlink" class="reference internal" href="#os.unlink"><tt class="xref docutils literal"><span class="pre">unlink()</span></tt></a> name is its traditional Unix name. Availability: Unix,
Windows.</dd></dl>

<dl class="function">
<dt id="os.utime">
<tt class="descclassname">os.</tt><tt class="descname">utime</tt><big>(</big><em>path</em>, <em>times</em><big>)</big><a class="headerlink" href="#os.utime" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the access and modified times of the file specified by <em>path</em>. If <em>times</em>
is <tt class="xref docutils literal"><span class="pre">None</span></tt>, then the file&#8217;s access and modified times are set to the current
time. (The effect is similar to running the Unix program <strong>touch</strong> on
the path.)  Otherwise, <em>times</em> must be a 2-tuple of numbers, of the form
<tt class="docutils literal"><span class="pre">(atime,</span> <span class="pre">mtime)</span></tt> which is used to set the access and modified times,
respectively. Whether a directory can be given for <em>path</em> depends on whether
the operating system implements directories as files (for example, Windows
does not).  Note that the exact times you set here may not be returned by a
subsequent <a title="os.stat" class="reference internal" href="#os.stat"><tt class="xref docutils literal"><span class="pre">stat()</span></tt></a> call, depending on the resolution with which your
operating system records access and modification times; see <a title="os.stat" class="reference internal" href="#os.stat"><tt class="xref docutils literal"><span class="pre">stat()</span></tt></a>.</p>
<p>
<span class="versionmodified">Changed in version 2.0: </span>Added support for <tt class="xref docutils literal"><span class="pre">None</span></tt> for <em>times</em>.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os.walk">
<tt class="descclassname">os.</tt><tt class="descname">walk</tt><big>(</big><em>top</em><span class="optional">[</span>, <em>topdown=True</em><span class="optional">[</span>, <em>onerror=None</em><span class="optional">[</span>, <em>followlinks=False</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.walk" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-445">Generate the file names in a directory tree by walking the tree
either top-down or bottom-up. For each directory in the tree rooted at directory
<em>top</em> (including <em>top</em> itself), it yields a 3-tuple <tt class="docutils literal"><span class="pre">(dirpath,</span> <span class="pre">dirnames,</span>
<span class="pre">filenames)</span></tt>.</p>
<p><em>dirpath</em> is a string, the path to the directory.  <em>dirnames</em> is a list of the
names of the subdirectories in <em>dirpath</em> (excluding <tt class="docutils literal"><span class="pre">'.'</span></tt> and <tt class="docutils literal"><span class="pre">'..'</span></tt>).
<em>filenames</em> is a list of the names of the non-directory files in <em>dirpath</em>.
Note that the names in the lists contain no path components.  To get a full path
(which begins with <em>top</em>) to a file or directory in <em>dirpath</em>, do
<tt class="docutils literal"><span class="pre">os.path.join(dirpath,</span> <span class="pre">name)</span></tt>.</p>
<p>If optional argument <em>topdown</em> is <tt class="xref docutils literal"><span class="pre">True</span></tt> or not specified, the triple for a
directory is generated before the triples for any of its subdirectories
(directories are generated top-down).  If <em>topdown</em> is <tt class="xref docutils literal"><span class="pre">False</span></tt>, the triple for a
directory is generated after the triples for all of its subdirectories
(directories are generated bottom-up).</p>
<p>When <em>topdown</em> is <tt class="xref docutils literal"><span class="pre">True</span></tt>, the caller can modify the <em>dirnames</em> list in-place
(perhaps using <a class="reference external" href="../reference/simple_stmts.html#del"><tt class="xref docutils literal"><span class="pre">del</span></tt></a> or slice assignment), and <a title="os.walk" class="reference internal" href="#os.walk"><tt class="xref docutils literal"><span class="pre">walk()</span></tt></a> will only
recurse into the subdirectories whose names remain in <em>dirnames</em>; this can be
used to prune the search, impose a specific order of visiting, or even to inform
<a title="os.walk" class="reference internal" href="#os.walk"><tt class="xref docutils literal"><span class="pre">walk()</span></tt></a> about directories the caller creates or renames before it resumes
<a title="os.walk" class="reference internal" href="#os.walk"><tt class="xref docutils literal"><span class="pre">walk()</span></tt></a> again.  Modifying <em>dirnames</em> when <em>topdown</em> is <tt class="xref docutils literal"><span class="pre">False</span></tt> is
ineffective, because in bottom-up mode the directories in <em>dirnames</em> are
generated before <em>dirpath</em> itself is generated.</p>
<p>By default errors from the <a title="os.listdir" class="reference internal" href="#os.listdir"><tt class="xref docutils literal"><span class="pre">listdir()</span></tt></a> call are ignored.  If optional
argument <em>onerror</em> is specified, it should be a function; it will be called with
one argument, an <a title="exceptions.OSError" class="reference external" href="exceptions.html#exceptions.OSError"><tt class="xref docutils literal"><span class="pre">OSError</span></tt></a> instance.  It can report the error to continue
with the walk, or raise the exception to abort the walk.  Note that the filename
is available as the <tt class="docutils literal"><span class="pre">filename</span></tt> attribute of the exception object.</p>
<p>By default, <a title="os.walk" class="reference internal" href="#os.walk"><tt class="xref docutils literal"><span class="pre">walk()</span></tt></a> will not walk down into symbolic links that resolve to
directories. Set <em>followlinks</em> to <tt class="xref docutils literal"><span class="pre">True</span></tt> to visit directories pointed to by
symlinks, on systems that support them.</p>
<p>
<span class="versionmodified">New in version 2.6: </span>The <em>followlinks</em> parameter.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Be aware that setting <em>followlinks</em> to <tt class="xref docutils literal"><span class="pre">True</span></tt> can lead to infinite recursion if a
link points to a parent directory of itself. <a title="os.walk" class="reference internal" href="#os.walk"><tt class="xref docutils literal"><span class="pre">walk()</span></tt></a> does not keep track of
the directories it visited already.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you pass a relative pathname, don&#8217;t change the current working directory
between resumptions of <a title="os.walk" class="reference internal" href="#os.walk"><tt class="xref docutils literal"><span class="pre">walk()</span></tt></a>.  <a title="os.walk" class="reference internal" href="#os.walk"><tt class="xref docutils literal"><span class="pre">walk()</span></tt></a> never changes the current
directory, and assumes that its caller doesn&#8217;t either.</p>
</div>
<p>This example displays the number of bytes taken by non-directory files in each
directory under the starting directory, except that it doesn&#8217;t look under any
CVS subdirectory:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">os.path</span> <span class="kn">import</span> <span class="n">join</span><span class="p">,</span> <span class="n">getsize</span>
<span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="s">&#39;python/Lib/email&#39;</span><span class="p">):</span>
    <span class="k">print</span> <span class="n">root</span><span class="p">,</span> <span class="s">&quot;consumes&quot;</span><span class="p">,</span>
    <span class="k">print</span> <span class="nb">sum</span><span class="p">(</span><span class="n">getsize</span><span class="p">(</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">files</span><span class="p">),</span>
    <span class="k">print</span> <span class="s">&quot;bytes in&quot;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">files</span><span class="p">),</span> <span class="s">&quot;non-directory files&quot;</span>
    <span class="k">if</span> <span class="s">&#39;CVS&#39;</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span>
        <span class="n">dirs</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s">&#39;CVS&#39;</span><span class="p">)</span>  <span class="c"># don&#39;t visit CVS directories</span>
</pre></div>
</div>
<p>In the next example, walking the tree bottom-up is essential: <a title="os.rmdir" class="reference internal" href="#os.rmdir"><tt class="xref docutils literal"><span class="pre">rmdir()</span></tt></a>
doesn&#8217;t allow deleting a directory before the directory is empty:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># Delete everything reachable from the directory named in &quot;top&quot;,</span>
<span class="c"># assuming there are no symbolic links.</span>
<span class="c"># CAUTION:  This is dangerous!  For example, if top == &#39;/&#39;, it</span>
<span class="c"># could delete all your disk files.</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="n">top</span><span class="p">,</span> <span class="n">topdown</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">files</span><span class="p">:</span>
        <span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span>
        <span class="n">os</span><span class="o">.</span><span class="n">rmdir</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span>
</pre></div>
</div>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

</div>
<div class="section" id="process-management">
<span id="os-process"></span><h2>16.1.5. Process Management<a class="headerlink" href="#process-management" title="Permalink to this headline">¶</a></h2>
<p>These functions may be used to create and manage processes.</p>
<p>The various <tt class="xref docutils literal"><span class="pre">exec*()</span></tt> functions take a list of arguments for the new
program loaded into the process.  In each case, the first of these arguments is
passed to the new program as its own name rather than as an argument a user may
have typed on a command line.  For the C programmer, this is the <tt class="docutils literal"><span class="pre">argv[0]</span></tt>
passed to a program&#8217;s <tt class="xref docutils literal"><span class="pre">main</span></tt>.  For example, <tt class="docutils literal"><span class="pre">os.execv('/bin/echo',</span>
<span class="pre">['foo',</span> <span class="pre">'bar'])</span></tt> will only print <tt class="docutils literal"><span class="pre">bar</span></tt> on standard output; <tt class="docutils literal"><span class="pre">foo</span></tt> will seem
to be ignored.</p>
<dl class="function">
<dt id="os.abort">
<tt class="descclassname">os.</tt><tt class="descname">abort</tt><big>(</big><big>)</big><a class="headerlink" href="#os.abort" title="Permalink to this definition">¶</a></dt>
<dd>Generate a <tt class="xref docutils literal"><span class="pre">SIGABRT</span></tt> signal to the current process.  On Unix, the default
behavior is to produce a core dump; on Windows, the process immediately returns
an exit code of <tt class="docutils literal"><span class="pre">3</span></tt>.  Be aware that programs which use <a title="signal.signal" class="reference external" href="signal.html#signal.signal"><tt class="xref docutils literal"><span class="pre">signal.signal()</span></tt></a>
to register a handler for <tt class="xref docutils literal"><span class="pre">SIGABRT</span></tt> will behave differently.
Availability: Unix, Windows.</dd></dl>

<dl class="function">
<dt id="os.execl">
<tt class="descclassname">os.</tt><tt class="descname">execl</tt><big>(</big><em>path</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.execl" title="Permalink to this definition">¶</a></dt>
<dt id="os.execle">
<tt class="descclassname">os.</tt><tt class="descname">execle</tt><big>(</big><em>path</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execle" title="Permalink to this definition">¶</a></dt>
<dt id="os.execlp">
<tt class="descclassname">os.</tt><tt class="descname">execlp</tt><big>(</big><em>file</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.execlp" title="Permalink to this definition">¶</a></dt>
<dt id="os.execlpe">
<tt class="descclassname">os.</tt><tt class="descname">execlpe</tt><big>(</big><em>file</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execlpe" title="Permalink to this definition">¶</a></dt>
<dt id="os.execv">
<tt class="descclassname">os.</tt><tt class="descname">execv</tt><big>(</big><em>path</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.execv" title="Permalink to this definition">¶</a></dt>
<dt id="os.execve">
<tt class="descclassname">os.</tt><tt class="descname">execve</tt><big>(</big><em>path</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execve" title="Permalink to this definition">¶</a></dt>
<dt id="os.execvp">
<tt class="descclassname">os.</tt><tt class="descname">execvp</tt><big>(</big><em>file</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.execvp" title="Permalink to this definition">¶</a></dt>
<dt id="os.execvpe">
<tt class="descclassname">os.</tt><tt class="descname">execvpe</tt><big>(</big><em>file</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execvpe" title="Permalink to this definition">¶</a></dt>
<dd><p>These functions all execute a new program, replacing the current process; they
do not return.  On Unix, the new executable is loaded into the current process,
and will have the same process id as the caller.  Errors will be reported as
<a title="exceptions.OSError" class="reference external" href="exceptions.html#exceptions.OSError"><tt class="xref docutils literal"><span class="pre">OSError</span></tt></a> exceptions.</p>
<p>The current process is replaced immediately. Open file objects and
descriptors are not flushed, so if there may be data buffered
on these open files, you should flush them using
<tt class="xref docutils literal"><span class="pre">sys.stdout.flush()</span></tt> or <a title="os.fsync" class="reference internal" href="#os.fsync"><tt class="xref docutils literal"><span class="pre">os.fsync()</span></tt></a> before calling an
<tt class="xref docutils literal"><span class="pre">exec*()</span></tt> function.</p>
<p>The &#8220;l&#8221; and &#8220;v&#8221; variants of the <tt class="xref docutils literal"><span class="pre">exec*()</span></tt> functions differ in how
command-line arguments are passed.  The &#8220;l&#8221; variants are perhaps the easiest
to work with if the number of parameters is fixed when the code is written; the
individual parameters simply become additional parameters to the <tt class="xref docutils literal"><span class="pre">execl*()</span></tt>
functions.  The &#8220;v&#8221; variants are good when the number of parameters is
variable, with the arguments being passed in a list or tuple as the <em>args</em>
parameter.  In either case, the arguments to the child process should start with
the name of the command being run, but this is not enforced.</p>
<p>The variants which include a &#8220;p&#8221; near the end (<a title="os.execlp" class="reference internal" href="#os.execlp"><tt class="xref docutils literal"><span class="pre">execlp()</span></tt></a>,
<a title="os.execlpe" class="reference internal" href="#os.execlpe"><tt class="xref docutils literal"><span class="pre">execlpe()</span></tt></a>, <a title="os.execvp" class="reference internal" href="#os.execvp"><tt class="xref docutils literal"><span class="pre">execvp()</span></tt></a>, and <a title="os.execvpe" class="reference internal" href="#os.execvpe"><tt class="xref docutils literal"><span class="pre">execvpe()</span></tt></a>) will use the
<span class="target" id="index-446"></span><strong class="xref">PATH</strong> environment variable to locate the program <em>file</em>.  When the
environment is being replaced (using one of the <tt class="xref docutils literal"><span class="pre">exec*e()</span></tt> variants,
discussed in the next paragraph), the new environment is used as the source of
the <span class="target" id="index-447"></span><strong class="xref">PATH</strong> variable. The other variants, <a title="os.execl" class="reference internal" href="#os.execl"><tt class="xref docutils literal"><span class="pre">execl()</span></tt></a>, <a title="os.execle" class="reference internal" href="#os.execle"><tt class="xref docutils literal"><span class="pre">execle()</span></tt></a>,
<a title="os.execv" class="reference internal" href="#os.execv"><tt class="xref docutils literal"><span class="pre">execv()</span></tt></a>, and <a title="os.execve" class="reference internal" href="#os.execve"><tt class="xref docutils literal"><span class="pre">execve()</span></tt></a>, will not use the <span class="target" id="index-448"></span><strong class="xref">PATH</strong> variable to
locate the executable; <em>path</em> must contain an appropriate absolute or relative
path.</p>
<p>For <a title="os.execle" class="reference internal" href="#os.execle"><tt class="xref docutils literal"><span class="pre">execle()</span></tt></a>, <a title="os.execlpe" class="reference internal" href="#os.execlpe"><tt class="xref docutils literal"><span class="pre">execlpe()</span></tt></a>, <a title="os.execve" class="reference internal" href="#os.execve"><tt class="xref docutils literal"><span class="pre">execve()</span></tt></a>, and <a title="os.execvpe" class="reference internal" href="#os.execvpe"><tt class="xref docutils literal"><span class="pre">execvpe()</span></tt></a> (note
that these all end in &#8220;e&#8221;), the <em>env</em> parameter must be a mapping which is
used to define the environment variables for the new process (these are used
instead of the current process&#8217; environment); the functions <a title="os.execl" class="reference internal" href="#os.execl"><tt class="xref docutils literal"><span class="pre">execl()</span></tt></a>,
<a title="os.execlp" class="reference internal" href="#os.execlp"><tt class="xref docutils literal"><span class="pre">execlp()</span></tt></a>, <a title="os.execv" class="reference internal" href="#os.execv"><tt class="xref docutils literal"><span class="pre">execv()</span></tt></a>, and <a title="os.execvp" class="reference internal" href="#os.execvp"><tt class="xref docutils literal"><span class="pre">execvp()</span></tt></a> all cause the new process to
inherit the environment of the current process.</p>
<p>Availability: Unix, Windows.</p>
</dd></dl>

<dl class="function">
<dt id="os._exit">
<tt class="descclassname">os.</tt><tt class="descname">_exit</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#os._exit" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit to the system with status <em>n</em>, without calling cleanup handlers, flushing
stdio buffers, etc. Availability: Unix, Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The standard way to exit is <tt class="docutils literal"><span class="pre">sys.exit(n)</span></tt>. <a title="os._exit" class="reference internal" href="#os._exit"><tt class="xref docutils literal"><span class="pre">_exit()</span></tt></a> should normally only
be used in the child process after a <a title="os.fork" class="reference internal" href="#os.fork"><tt class="xref docutils literal"><span class="pre">fork()</span></tt></a>.</p>
</div>
</dd></dl>

<p>The following exit codes are defined and can be used with <a title="os._exit" class="reference internal" href="#os._exit"><tt class="xref docutils literal"><span class="pre">_exit()</span></tt></a>,
although they are not required.  These are typically used for system programs
written in Python, such as a mail server&#8217;s external command delivery program.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Some of these may not be available on all Unix platforms, since there is some
variation.  These constants are defined where they are defined by the underlying
platform.</p>
</div>
<dl class="data">
<dt id="os.EX_OK">
<tt class="descclassname">os.</tt><tt class="descname">EX_OK</tt><a class="headerlink" href="#os.EX_OK" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means no error occurred. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_USAGE">
<tt class="descclassname">os.</tt><tt class="descname">EX_USAGE</tt><a class="headerlink" href="#os.EX_USAGE" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means the command was used incorrectly, such as when the wrong
number of arguments are given. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_DATAERR">
<tt class="descclassname">os.</tt><tt class="descname">EX_DATAERR</tt><a class="headerlink" href="#os.EX_DATAERR" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means the input data was incorrect. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_NOINPUT">
<tt class="descclassname">os.</tt><tt class="descname">EX_NOINPUT</tt><a class="headerlink" href="#os.EX_NOINPUT" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means an input file did not exist or was not readable.
Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_NOUSER">
<tt class="descclassname">os.</tt><tt class="descname">EX_NOUSER</tt><a class="headerlink" href="#os.EX_NOUSER" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means a specified user did not exist. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_NOHOST">
<tt class="descclassname">os.</tt><tt class="descname">EX_NOHOST</tt><a class="headerlink" href="#os.EX_NOHOST" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means a specified host did not exist. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_UNAVAILABLE">
<tt class="descclassname">os.</tt><tt class="descname">EX_UNAVAILABLE</tt><a class="headerlink" href="#os.EX_UNAVAILABLE" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means that a required service is unavailable. Availability:
Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_SOFTWARE">
<tt class="descclassname">os.</tt><tt class="descname">EX_SOFTWARE</tt><a class="headerlink" href="#os.EX_SOFTWARE" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means an internal software error was detected. Availability:
Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_OSERR">
<tt class="descclassname">os.</tt><tt class="descname">EX_OSERR</tt><a class="headerlink" href="#os.EX_OSERR" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means an operating system error was detected, such as the
inability to fork or create a pipe. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_OSFILE">
<tt class="descclassname">os.</tt><tt class="descname">EX_OSFILE</tt><a class="headerlink" href="#os.EX_OSFILE" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means some system file did not exist, could not be opened, or had
some other kind of error. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_CANTCREAT">
<tt class="descclassname">os.</tt><tt class="descname">EX_CANTCREAT</tt><a class="headerlink" href="#os.EX_CANTCREAT" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means a user specified output file could not be created.
Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_IOERR">
<tt class="descclassname">os.</tt><tt class="descname">EX_IOERR</tt><a class="headerlink" href="#os.EX_IOERR" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means that an error occurred while doing I/O on some file.
Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_TEMPFAIL">
<tt class="descclassname">os.</tt><tt class="descname">EX_TEMPFAIL</tt><a class="headerlink" href="#os.EX_TEMPFAIL" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means a temporary failure occurred.  This indicates something
that may not really be an error, such as a network connection that couldn&#8217;t be
made during a retryable operation. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_PROTOCOL">
<tt class="descclassname">os.</tt><tt class="descname">EX_PROTOCOL</tt><a class="headerlink" href="#os.EX_PROTOCOL" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means that a protocol exchange was illegal, invalid, or not
understood. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_NOPERM">
<tt class="descclassname">os.</tt><tt class="descname">EX_NOPERM</tt><a class="headerlink" href="#os.EX_NOPERM" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means that there were insufficient permissions to perform the
operation (but not intended for file system problems). Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_CONFIG">
<tt class="descclassname">os.</tt><tt class="descname">EX_CONFIG</tt><a class="headerlink" href="#os.EX_CONFIG" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means that some kind of configuration error occurred.
Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.EX_NOTFOUND">
<tt class="descclassname">os.</tt><tt class="descname">EX_NOTFOUND</tt><a class="headerlink" href="#os.EX_NOTFOUND" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit code that means something like &#8220;an entry was not found&#8221;. Availability:
Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.fork">
<tt class="descclassname">os.</tt><tt class="descname">fork</tt><big>(</big><big>)</big><a class="headerlink" href="#os.fork" title="Permalink to this definition">¶</a></dt>
<dd><p>Fork a child process.  Return <tt class="docutils literal"><span class="pre">0</span></tt> in the child and the child&#8217;s process id in the
parent.  If an error occurs <a title="exceptions.OSError" class="reference external" href="exceptions.html#exceptions.OSError"><tt class="xref docutils literal"><span class="pre">OSError</span></tt></a> is raised.</p>
<p>Note that some platforms including FreeBSD &lt;= 6.3, Cygwin and OS/2 EMX have
known issues when using fork() from a thread.</p>
<p>Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.forkpty">
<tt class="descclassname">os.</tt><tt class="descname">forkpty</tt><big>(</big><big>)</big><a class="headerlink" href="#os.forkpty" title="Permalink to this definition">¶</a></dt>
<dd>Fork a child process, using a new pseudo-terminal as the child&#8217;s controlling
terminal. Return a pair of <tt class="docutils literal"><span class="pre">(pid,</span> <span class="pre">fd)</span></tt>, where <em>pid</em> is <tt class="docutils literal"><span class="pre">0</span></tt> in the child, the
new child&#8217;s process id in the parent, and <em>fd</em> is the file descriptor of the
master end of the pseudo-terminal.  For a more portable approach, use the
<a title="(IRIX, Linux) Pseudo-Terminal Handling for SGI and Linux." class="reference external" href="pty.html#module-pty"><tt class="xref docutils literal"><span class="pre">pty</span></tt></a> module.  If an error occurs <a title="exceptions.OSError" class="reference external" href="exceptions.html#exceptions.OSError"><tt class="xref docutils literal"><span class="pre">OSError</span></tt></a> is raised.
Availability: some flavors of Unix.</dd></dl>

<dl class="function">
<dt id="os.kill">
<tt class="descclassname">os.</tt><tt class="descname">kill</tt><big>(</big><em>pid</em>, <em>sig</em><big>)</big><a class="headerlink" href="#os.kill" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-449">Send signal <em>sig</em> to the process <em>pid</em>.  Constants for the specific signals
available on the host platform are defined in the <a title="Set handlers for asynchronous events." class="reference external" href="signal.html#module-signal"><tt class="xref docutils literal"><span class="pre">signal</span></tt></a> module.
Availability: Unix.</p>
</dd></dl>

<dl class="function">
<dt id="os.killpg">
<tt class="descclassname">os.</tt><tt class="descname">killpg</tt><big>(</big><em>pgid</em>, <em>sig</em><big>)</big><a class="headerlink" href="#os.killpg" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-450">Send the signal <em>sig</em> to the process group <em>pgid</em>. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.nice">
<tt class="descclassname">os.</tt><tt class="descname">nice</tt><big>(</big><em>increment</em><big>)</big><a class="headerlink" href="#os.nice" title="Permalink to this definition">¶</a></dt>
<dd>Add <em>increment</em> to the process&#8217;s &#8220;niceness&#8221;.  Return the new niceness.
Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.plock">
<tt class="descclassname">os.</tt><tt class="descname">plock</tt><big>(</big><em>op</em><big>)</big><a class="headerlink" href="#os.plock" title="Permalink to this definition">¶</a></dt>
<dd>Lock program segments into memory.  The value of <em>op</em> (defined in
<tt class="docutils literal"><span class="pre">&lt;sys/lock.h&gt;</span></tt>) determines which segments are locked. Availability: Unix.</dd></dl>

<dl class="function">
<dt>
<tt class="descclassname">os.</tt><tt class="descname">popen</tt><big>(</big><em>...</em><big>)</big></dt>
<dt>
<tt class="descclassname">os.</tt><tt class="descname">popen2</tt><big>(</big><em>...</em><big>)</big></dt>
<dt>
<tt class="descclassname">os.</tt><tt class="descname">popen3</tt><big>(</big><em>...</em><big>)</big></dt>
<dt>
<tt class="descclassname">os.</tt><tt class="descname">popen4</tt><big>(</big><em>...</em><big>)</big></dt>
<dd>Run child processes, returning opened pipes for communications.  These functions
are described in section <a class="reference internal" href="#os-newstreams"><em>File Object Creation</em></a>.</dd></dl>

<dl class="function">
<dt id="os.spawnl">
<tt class="descclassname">os.</tt><tt class="descname">spawnl</tt><big>(</big><em>mode</em>, <em>path</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.spawnl" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnle">
<tt class="descclassname">os.</tt><tt class="descname">spawnle</tt><big>(</big><em>mode</em>, <em>path</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnle" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnlp">
<tt class="descclassname">os.</tt><tt class="descname">spawnlp</tt><big>(</big><em>mode</em>, <em>file</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.spawnlp" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnlpe">
<tt class="descclassname">os.</tt><tt class="descname">spawnlpe</tt><big>(</big><em>mode</em>, <em>file</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnlpe" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnv">
<tt class="descclassname">os.</tt><tt class="descname">spawnv</tt><big>(</big><em>mode</em>, <em>path</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.spawnv" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnve">
<tt class="descclassname">os.</tt><tt class="descname">spawnve</tt><big>(</big><em>mode</em>, <em>path</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnve" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnvp">
<tt class="descclassname">os.</tt><tt class="descname">spawnvp</tt><big>(</big><em>mode</em>, <em>file</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.spawnvp" title="Permalink to this definition">¶</a></dt>
<dt id="os.spawnvpe">
<tt class="descclassname">os.</tt><tt class="descname">spawnvpe</tt><big>(</big><em>mode</em>, <em>file</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnvpe" title="Permalink to this definition">¶</a></dt>
<dd><p>Execute the program <em>path</em> in a new process.</p>
<p>(Note that the <a title="Subprocess management." class="reference external" href="subprocess.html#module-subprocess"><tt class="xref docutils literal"><span class="pre">subprocess</span></tt></a> module provides more powerful facilities for
spawning new processes and retrieving their results; using that module is
preferable to using these functions.  Check specially the <em>Replacing Older
Functions with the subprocess Module</em> section in that documentation page.)</p>
<p>If <em>mode</em> is <a title="os.P_NOWAIT" class="reference internal" href="#os.P_NOWAIT"><tt class="xref docutils literal"><span class="pre">P_NOWAIT</span></tt></a>, this function returns the process id of the new
process; if <em>mode</em> is <a title="os.P_WAIT" class="reference internal" href="#os.P_WAIT"><tt class="xref docutils literal"><span class="pre">P_WAIT</span></tt></a>, returns the process&#8217;s exit code if it
exits normally, or <tt class="docutils literal"><span class="pre">-signal</span></tt>, where <em>signal</em> is the signal that killed the
process.  On Windows, the process id will actually be the process handle, so can
be used with the <a title="os.waitpid" class="reference internal" href="#os.waitpid"><tt class="xref docutils literal"><span class="pre">waitpid()</span></tt></a> function.</p>
<p>The &#8220;l&#8221; and &#8220;v&#8221; variants of the <tt class="xref docutils literal"><span class="pre">spawn*()</span></tt> functions differ in how
command-line arguments are passed.  The &#8220;l&#8221; variants are perhaps the easiest
to work with if the number of parameters is fixed when the code is written; the
individual parameters simply become additional parameters to the
<tt class="xref docutils literal"><span class="pre">spawnl*()</span></tt> functions.  The &#8220;v&#8221; variants are good when the number of
parameters is variable, with the arguments being passed in a list or tuple as
the <em>args</em> parameter.  In either case, the arguments to the child process must
start with the name of the command being run.</p>
<p>The variants which include a second &#8220;p&#8221; near the end (<a title="os.spawnlp" class="reference internal" href="#os.spawnlp"><tt class="xref docutils literal"><span class="pre">spawnlp()</span></tt></a>,
<a title="os.spawnlpe" class="reference internal" href="#os.spawnlpe"><tt class="xref docutils literal"><span class="pre">spawnlpe()</span></tt></a>, <a title="os.spawnvp" class="reference internal" href="#os.spawnvp"><tt class="xref docutils literal"><span class="pre">spawnvp()</span></tt></a>, and <a title="os.spawnvpe" class="reference internal" href="#os.spawnvpe"><tt class="xref docutils literal"><span class="pre">spawnvpe()</span></tt></a>) will use the
<span class="target" id="index-451"></span><strong class="xref">PATH</strong> environment variable to locate the program <em>file</em>.  When the
environment is being replaced (using one of the <tt class="xref docutils literal"><span class="pre">spawn*e()</span></tt> variants,
discussed in the next paragraph), the new environment is used as the source of
the <span class="target" id="index-452"></span><strong class="xref">PATH</strong> variable.  The other variants, <a title="os.spawnl" class="reference internal" href="#os.spawnl"><tt class="xref docutils literal"><span class="pre">spawnl()</span></tt></a>,
<a title="os.spawnle" class="reference internal" href="#os.spawnle"><tt class="xref docutils literal"><span class="pre">spawnle()</span></tt></a>, <a title="os.spawnv" class="reference internal" href="#os.spawnv"><tt class="xref docutils literal"><span class="pre">spawnv()</span></tt></a>, and <a title="os.spawnve" class="reference internal" href="#os.spawnve"><tt class="xref docutils literal"><span class="pre">spawnve()</span></tt></a>, will not use the
<span class="target" id="index-453"></span><strong class="xref">PATH</strong> variable to locate the executable; <em>path</em> must contain an
appropriate absolute or relative path.</p>
<p>For <a title="os.spawnle" class="reference internal" href="#os.spawnle"><tt class="xref docutils literal"><span class="pre">spawnle()</span></tt></a>, <a title="os.spawnlpe" class="reference internal" href="#os.spawnlpe"><tt class="xref docutils literal"><span class="pre">spawnlpe()</span></tt></a>, <a title="os.spawnve" class="reference internal" href="#os.spawnve"><tt class="xref docutils literal"><span class="pre">spawnve()</span></tt></a>, and <a title="os.spawnvpe" class="reference internal" href="#os.spawnvpe"><tt class="xref docutils literal"><span class="pre">spawnvpe()</span></tt></a>
(note that these all end in &#8220;e&#8221;), the <em>env</em> parameter must be a mapping
which is used to define the environment variables for the new process (they are
used instead of the current process&#8217; environment); the functions
<a title="os.spawnl" class="reference internal" href="#os.spawnl"><tt class="xref docutils literal"><span class="pre">spawnl()</span></tt></a>, <a title="os.spawnlp" class="reference internal" href="#os.spawnlp"><tt class="xref docutils literal"><span class="pre">spawnlp()</span></tt></a>, <a title="os.spawnv" class="reference internal" href="#os.spawnv"><tt class="xref docutils literal"><span class="pre">spawnv()</span></tt></a>, and <a title="os.spawnvp" class="reference internal" href="#os.spawnvp"><tt class="xref docutils literal"><span class="pre">spawnvp()</span></tt></a> all cause
the new process to inherit the environment of the current process.  Note that
keys and values in the <em>env</em> dictionary must be strings; invalid keys or
values will cause the function to fail, with a return value of <tt class="docutils literal"><span class="pre">127</span></tt>.</p>
<p>As an example, the following calls to <a title="os.spawnlp" class="reference internal" href="#os.spawnlp"><tt class="xref docutils literal"><span class="pre">spawnlp()</span></tt></a> and <a title="os.spawnvpe" class="reference internal" href="#os.spawnvpe"><tt class="xref docutils literal"><span class="pre">spawnvpe()</span></tt></a> are
equivalent:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span>
<span class="n">os</span><span class="o">.</span><span class="n">spawnlp</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">P_WAIT</span><span class="p">,</span> <span class="s">&#39;cp&#39;</span><span class="p">,</span> <span class="s">&#39;cp&#39;</span><span class="p">,</span> <span class="s">&#39;index.html&#39;</span><span class="p">,</span> <span class="s">&#39;/dev/null&#39;</span><span class="p">)</span>

<span class="n">L</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;cp&#39;</span><span class="p">,</span> <span class="s">&#39;index.html&#39;</span><span class="p">,</span> <span class="s">&#39;/dev/null&#39;</span><span class="p">]</span>
<span class="n">os</span><span class="o">.</span><span class="n">spawnvpe</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">P_WAIT</span><span class="p">,</span> <span class="s">&#39;cp&#39;</span><span class="p">,</span> <span class="n">L</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">)</span>
</pre></div>
</div>
<p>Availability: Unix, Windows.  <a title="os.spawnlp" class="reference internal" href="#os.spawnlp"><tt class="xref docutils literal"><span class="pre">spawnlp()</span></tt></a>, <a title="os.spawnlpe" class="reference internal" href="#os.spawnlpe"><tt class="xref docutils literal"><span class="pre">spawnlpe()</span></tt></a>, <a title="os.spawnvp" class="reference internal" href="#os.spawnvp"><tt class="xref docutils literal"><span class="pre">spawnvp()</span></tt></a>
and <a title="os.spawnvpe" class="reference internal" href="#os.spawnvpe"><tt class="xref docutils literal"><span class="pre">spawnvpe()</span></tt></a> are not available on Windows.</p>
<p>
<span class="versionmodified">New in version 1.6.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.P_NOWAIT">
<tt class="descclassname">os.</tt><tt class="descname">P_NOWAIT</tt><a class="headerlink" href="#os.P_NOWAIT" title="Permalink to this definition">¶</a></dt>
<dt id="os.P_NOWAITO">
<tt class="descclassname">os.</tt><tt class="descname">P_NOWAITO</tt><a class="headerlink" href="#os.P_NOWAITO" title="Permalink to this definition">¶</a></dt>
<dd><p>Possible values for the <em>mode</em> parameter to the <tt class="xref docutils literal"><span class="pre">spawn*()</span></tt> family of
functions.  If either of these values is given, the <tt class="xref docutils literal"><span class="pre">spawn*()</span></tt> functions
will return as soon as the new process has been created, with the process id as
the return value. Availability: Unix, Windows.</p>
<p>
<span class="versionmodified">New in version 1.6.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.P_WAIT">
<tt class="descclassname">os.</tt><tt class="descname">P_WAIT</tt><a class="headerlink" href="#os.P_WAIT" title="Permalink to this definition">¶</a></dt>
<dd><p>Possible value for the <em>mode</em> parameter to the <tt class="xref docutils literal"><span class="pre">spawn*()</span></tt> family of
functions.  If this is given as <em>mode</em>, the <tt class="xref docutils literal"><span class="pre">spawn*()</span></tt> functions will not
return until the new process has run to completion and will return the exit code
of the process the run is successful, or <tt class="docutils literal"><span class="pre">-signal</span></tt> if a signal kills the
process. Availability: Unix, Windows.</p>
<p>
<span class="versionmodified">New in version 1.6.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.P_DETACH">
<tt class="descclassname">os.</tt><tt class="descname">P_DETACH</tt><a class="headerlink" href="#os.P_DETACH" title="Permalink to this definition">¶</a></dt>
<dt id="os.P_OVERLAY">
<tt class="descclassname">os.</tt><tt class="descname">P_OVERLAY</tt><a class="headerlink" href="#os.P_OVERLAY" title="Permalink to this definition">¶</a></dt>
<dd><p>Possible values for the <em>mode</em> parameter to the <tt class="xref docutils literal"><span class="pre">spawn*()</span></tt> family of
functions.  These are less portable than those listed above. <a title="os.P_DETACH" class="reference internal" href="#os.P_DETACH"><tt class="xref docutils literal"><span class="pre">P_DETACH</span></tt></a>
is similar to <a title="os.P_NOWAIT" class="reference internal" href="#os.P_NOWAIT"><tt class="xref docutils literal"><span class="pre">P_NOWAIT</span></tt></a>, but the new process is detached from the
console of the calling process. If <a title="os.P_OVERLAY" class="reference internal" href="#os.P_OVERLAY"><tt class="xref docutils literal"><span class="pre">P_OVERLAY</span></tt></a> is used, the current
process will be replaced; the <tt class="xref docutils literal"><span class="pre">spawn*()</span></tt> function will not return.
Availability: Windows.</p>
<p>
<span class="versionmodified">New in version 1.6.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.startfile">
<tt class="descclassname">os.</tt><tt class="descname">startfile</tt><big>(</big><em>path</em><span class="optional">[</span>, <em>operation</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.startfile" title="Permalink to this definition">¶</a></dt>
<dd><p>Start a file with its associated application.</p>
<p>When <em>operation</em> is not specified or <tt class="docutils literal"><span class="pre">'open'</span></tt>, this acts like double-clicking
the file in Windows Explorer, or giving the file name as an argument to the
<strong>start</strong> command from the interactive command shell: the file is opened
with whatever application (if any) its extension is associated.</p>
<p>When another <em>operation</em> is given, it must be a &#8220;command verb&#8221; that specifies
what should be done with the file. Common verbs documented by Microsoft are
<tt class="docutils literal"><span class="pre">'print'</span></tt> and  <tt class="docutils literal"><span class="pre">'edit'</span></tt> (to be used on files) as well as <tt class="docutils literal"><span class="pre">'explore'</span></tt> and
<tt class="docutils literal"><span class="pre">'find'</span></tt> (to be used on directories).</p>
<p><a title="os.startfile" class="reference internal" href="#os.startfile"><tt class="xref docutils literal"><span class="pre">startfile()</span></tt></a> returns as soon as the associated application is launched.
There is no option to wait for the application to close, and no way to retrieve
the application&#8217;s exit status.  The <em>path</em> parameter is relative to the current
directory.  If you want to use an absolute path, make sure the first character
is not a slash (<tt class="docutils literal"><span class="pre">'/'</span></tt>); the underlying Win32 <tt class="xref docutils literal"><span class="pre">ShellExecute</span></tt> function
doesn&#8217;t work if it is.  Use the <a title="os.path.normpath" class="reference external" href="os.path.html#os.path.normpath"><tt class="xref docutils literal"><span class="pre">os.path.normpath()</span></tt></a> function to ensure that
the path is properly encoded for Win32. Availability: Windows.</p>
<p>
<span class="versionmodified">New in version 2.0.</span></p>
<p>
<span class="versionmodified">New in version 2.5: </span>The <em>operation</em> parameter.</p>
</dd></dl>

<dl class="function">
<dt id="os.system">
<tt class="descclassname">os.</tt><tt class="descname">system</tt><big>(</big><em>command</em><big>)</big><a class="headerlink" href="#os.system" title="Permalink to this definition">¶</a></dt>
<dd><p>Execute the command (a string) in a subshell.  This is implemented by calling
the Standard C function <tt class="xref docutils literal"><span class="pre">system</span></tt>, and has the same limitations.  Changes
to <a title="os.environ" class="reference internal" href="#os.environ"><tt class="xref docutils literal"><span class="pre">os.environ</span></tt></a>, <a title="sys.stdin" class="reference external" href="sys.html#sys.stdin"><tt class="xref docutils literal"><span class="pre">sys.stdin</span></tt></a>, etc. are not reflected in the
environment of the executed command.</p>
<p>On Unix, the return value is the exit status of the process encoded in the
format specified for <a title="os.wait" class="reference internal" href="#os.wait"><tt class="xref docutils literal"><span class="pre">wait()</span></tt></a>.  Note that POSIX does not specify the meaning
of the return value of the C <tt class="xref docutils literal"><span class="pre">system</span></tt> function, so the return value of
the Python function is system-dependent.</p>
<p>On Windows, the return value is that returned by the system shell after running
<em>command</em>, given by the Windows environment variable <span class="target" id="index-454"></span><strong class="xref">COMSPEC</strong>: on
<strong>command.com</strong> systems (Windows 95, 98 and ME) this is always <tt class="docutils literal"><span class="pre">0</span></tt>; on
<strong>cmd.exe</strong> systems (Windows NT, 2000 and XP) this is the exit status of
the command run; on systems using a non-native shell, consult your shell
documentation.</p>
<p>Availability: Unix, Windows.</p>
<p>The <a title="Subprocess management." class="reference external" href="subprocess.html#module-subprocess"><tt class="xref docutils literal"><span class="pre">subprocess</span></tt></a> module provides more powerful facilities for spawning new
processes and retrieving their results; using that module is preferable to using
this function.  Use the <a title="Subprocess management." class="reference external" href="subprocess.html#module-subprocess"><tt class="xref docutils literal"><span class="pre">subprocess</span></tt></a> module.  Check especially the
<a class="reference external" href="subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section.</p>
</dd></dl>

<dl class="function">
<dt id="os.times">
<tt class="descclassname">os.</tt><tt class="descname">times</tt><big>(</big><big>)</big><a class="headerlink" href="#os.times" title="Permalink to this definition">¶</a></dt>
<dd>Return a 5-tuple of floating point numbers indicating accumulated (processor or
other) times, in seconds.  The items are: user time, system time, children&#8217;s
user time, children&#8217;s system time, and elapsed real time since a fixed point in
the past, in that order.  See the Unix manual page <em>times(2)</em> or the
corresponding Windows Platform API documentation. Availability: Unix,
Windows.  On Windows, only the first two items are filled, the others are zero.</dd></dl>

<dl class="function">
<dt id="os.wait">
<tt class="descclassname">os.</tt><tt class="descname">wait</tt><big>(</big><big>)</big><a class="headerlink" href="#os.wait" title="Permalink to this definition">¶</a></dt>
<dd>Wait for completion of a child process, and return a tuple containing its pid
and exit status indication: a 16-bit number, whose low byte is the signal number
that killed the process, and whose high byte is the exit status (if the signal
number is zero); the high bit of the low byte is set if a core file was
produced. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.waitpid">
<tt class="descclassname">os.</tt><tt class="descname">waitpid</tt><big>(</big><em>pid</em>, <em>options</em><big>)</big><a class="headerlink" href="#os.waitpid" title="Permalink to this definition">¶</a></dt>
<dd><p>The details of this function differ on Unix and Windows.</p>
<p>On Unix: Wait for completion of a child process given by process id <em>pid</em>, and
return a tuple containing its process id and exit status indication (encoded as
for <a title="os.wait" class="reference internal" href="#os.wait"><tt class="xref docutils literal"><span class="pre">wait()</span></tt></a>).  The semantics of the call are affected by the value of the
integer <em>options</em>, which should be <tt class="docutils literal"><span class="pre">0</span></tt> for normal operation.</p>
<p>If <em>pid</em> is greater than <tt class="docutils literal"><span class="pre">0</span></tt>, <a title="os.waitpid" class="reference internal" href="#os.waitpid"><tt class="xref docutils literal"><span class="pre">waitpid()</span></tt></a> requests status information for
that specific process.  If <em>pid</em> is <tt class="docutils literal"><span class="pre">0</span></tt>, the request is for the status of any
child in the process group of the current process.  If <em>pid</em> is <tt class="docutils literal"><span class="pre">-1</span></tt>, the
request pertains to any child of the current process.  If <em>pid</em> is less than
<tt class="docutils literal"><span class="pre">-1</span></tt>, status is requested for any process in the process group <tt class="docutils literal"><span class="pre">-pid</span></tt> (the
absolute value of <em>pid</em>).</p>
<p>An <a title="exceptions.OSError" class="reference external" href="exceptions.html#exceptions.OSError"><tt class="xref docutils literal"><span class="pre">OSError</span></tt></a> is raised with the value of errno when the syscall
returns -1.</p>
<p>On Windows: Wait for completion of a process given by process handle <em>pid</em>, and
return a tuple containing <em>pid</em>, and its exit status shifted left by 8 bits
(shifting makes cross-platform use of the function easier). A <em>pid</em> less than or
equal to <tt class="docutils literal"><span class="pre">0</span></tt> has no special meaning on Windows, and raises an exception. The
value of integer <em>options</em> has no effect. <em>pid</em> can refer to any process whose
id is known, not necessarily a child process. The <tt class="xref docutils literal"><span class="pre">spawn()</span></tt> functions called
with <a title="os.P_NOWAIT" class="reference internal" href="#os.P_NOWAIT"><tt class="xref docutils literal"><span class="pre">P_NOWAIT</span></tt></a> return suitable process handles.</p>
</dd></dl>

<dl class="function">
<dt id="os.wait3">
<tt class="descclassname">os.</tt><tt class="descname">wait3</tt><big>(</big><span class="optional">[</span><em>options</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.wait3" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a title="os.waitpid" class="reference internal" href="#os.waitpid"><tt class="xref docutils literal"><span class="pre">waitpid()</span></tt></a>, except no process id argument is given and a
3-element tuple containing the child&#8217;s process id, exit status indication, and
resource usage information is returned.  Refer to <a title="(Unix) An interface to provide resource usage information on the current process." class="reference external" href="resource.html#module-resource"><tt class="xref docutils literal"><span class="pre">resource</span></tt></a>.<tt class="xref docutils literal"><span class="pre">getrusage()</span></tt> for details on resource usage information.  The option
argument is the same as that provided to <a title="os.waitpid" class="reference internal" href="#os.waitpid"><tt class="xref docutils literal"><span class="pre">waitpid()</span></tt></a> and <a title="os.wait4" class="reference internal" href="#os.wait4"><tt class="xref docutils literal"><span class="pre">wait4()</span></tt></a>.
Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.5.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.wait4">
<tt class="descclassname">os.</tt><tt class="descname">wait4</tt><big>(</big><em>pid</em>, <em>options</em><big>)</big><a class="headerlink" href="#os.wait4" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a title="os.waitpid" class="reference internal" href="#os.waitpid"><tt class="xref docutils literal"><span class="pre">waitpid()</span></tt></a>, except a 3-element tuple, containing the child&#8217;s
process id, exit status indication, and resource usage information is returned.
Refer to <a title="(Unix) An interface to provide resource usage information on the current process." class="reference external" href="resource.html#module-resource"><tt class="xref docutils literal"><span class="pre">resource</span></tt></a>.<tt class="xref docutils literal"><span class="pre">getrusage()</span></tt> for details on resource usage
information.  The arguments to <a title="os.wait4" class="reference internal" href="#os.wait4"><tt class="xref docutils literal"><span class="pre">wait4()</span></tt></a> are the same as those provided to
<a title="os.waitpid" class="reference internal" href="#os.waitpid"><tt class="xref docutils literal"><span class="pre">waitpid()</span></tt></a>. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.5.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.WNOHANG">
<tt class="descclassname">os.</tt><tt class="descname">WNOHANG</tt><a class="headerlink" href="#os.WNOHANG" title="Permalink to this definition">¶</a></dt>
<dd>The option for <a title="os.waitpid" class="reference internal" href="#os.waitpid"><tt class="xref docutils literal"><span class="pre">waitpid()</span></tt></a> to return immediately if no child process status
is available immediately. The function returns <tt class="docutils literal"><span class="pre">(0,</span> <span class="pre">0)</span></tt> in this case.
Availability: Unix.</dd></dl>

<dl class="data">
<dt id="os.WCONTINUED">
<tt class="descclassname">os.</tt><tt class="descname">WCONTINUED</tt><a class="headerlink" href="#os.WCONTINUED" title="Permalink to this definition">¶</a></dt>
<dd><p>This option causes child processes to be reported if they have been continued
from a job control stop since their status was last reported. Availability: Some
Unix systems.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.WUNTRACED">
<tt class="descclassname">os.</tt><tt class="descname">WUNTRACED</tt><a class="headerlink" href="#os.WUNTRACED" title="Permalink to this definition">¶</a></dt>
<dd><p>This option causes child processes to be reported if they have been stopped but
their current state has not been reported since they were stopped. Availability:
Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<p>The following functions take a process status code as returned by
<a title="os.system" class="reference internal" href="#os.system"><tt class="xref docutils literal"><span class="pre">system()</span></tt></a>, <a title="os.wait" class="reference internal" href="#os.wait"><tt class="xref docutils literal"><span class="pre">wait()</span></tt></a>, or <a title="os.waitpid" class="reference internal" href="#os.waitpid"><tt class="xref docutils literal"><span class="pre">waitpid()</span></tt></a> as a parameter.  They may be
used to determine the disposition of a process.</p>
<dl class="function">
<dt id="os.WCOREDUMP">
<tt class="descclassname">os.</tt><tt class="descname">WCOREDUMP</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WCOREDUMP" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <tt class="xref docutils literal"><span class="pre">True</span></tt> if a core dump was generated for the process, otherwise
return <tt class="xref docutils literal"><span class="pre">False</span></tt>. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.WIFCONTINUED">
<tt class="descclassname">os.</tt><tt class="descname">WIFCONTINUED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFCONTINUED" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <tt class="xref docutils literal"><span class="pre">True</span></tt> if the process has been continued from a job control stop,
otherwise return <tt class="xref docutils literal"><span class="pre">False</span></tt>. Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.WIFSTOPPED">
<tt class="descclassname">os.</tt><tt class="descname">WIFSTOPPED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFSTOPPED" title="Permalink to this definition">¶</a></dt>
<dd>Return <tt class="xref docutils literal"><span class="pre">True</span></tt> if the process has been stopped, otherwise return
<tt class="xref docutils literal"><span class="pre">False</span></tt>. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.WIFSIGNALED">
<tt class="descclassname">os.</tt><tt class="descname">WIFSIGNALED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFSIGNALED" title="Permalink to this definition">¶</a></dt>
<dd>Return <tt class="xref docutils literal"><span class="pre">True</span></tt> if the process exited due to a signal, otherwise return
<tt class="xref docutils literal"><span class="pre">False</span></tt>. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.WIFEXITED">
<tt class="descclassname">os.</tt><tt class="descname">WIFEXITED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFEXITED" title="Permalink to this definition">¶</a></dt>
<dd>Return <tt class="xref docutils literal"><span class="pre">True</span></tt> if the process exited using the <em>exit(2)</em> system call,
otherwise return <tt class="xref docutils literal"><span class="pre">False</span></tt>. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.WEXITSTATUS">
<tt class="descclassname">os.</tt><tt class="descname">WEXITSTATUS</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WEXITSTATUS" title="Permalink to this definition">¶</a></dt>
<dd>If <tt class="docutils literal"><span class="pre">WIFEXITED(status)</span></tt> is true, return the integer parameter to the
<em>exit(2)</em> system call.  Otherwise, the return value is meaningless.
Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.WSTOPSIG">
<tt class="descclassname">os.</tt><tt class="descname">WSTOPSIG</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WSTOPSIG" title="Permalink to this definition">¶</a></dt>
<dd>Return the signal which caused the process to stop. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.WTERMSIG">
<tt class="descclassname">os.</tt><tt class="descname">WTERMSIG</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WTERMSIG" title="Permalink to this definition">¶</a></dt>
<dd>Return the signal which caused the process to exit. Availability: Unix.</dd></dl>

</div>
<div class="section" id="miscellaneous-system-information">
<span id="os-path"></span><h2>16.1.6. Miscellaneous System Information<a class="headerlink" href="#miscellaneous-system-information" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="os.confstr">
<tt class="descclassname">os.</tt><tt class="descname">confstr</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#os.confstr" title="Permalink to this definition">¶</a></dt>
<dd><p>Return string-valued system configuration values. <em>name</em> specifies the
configuration value to retrieve; it may be a string which is the name of a
defined system value; these names are specified in a number of standards (POSIX,
Unix 95, Unix 98, and others).  Some platforms define additional names as well.
The names known to the host operating system are given as the keys of the
<tt class="docutils literal"><span class="pre">confstr_names</span></tt> dictionary.  For configuration variables not included in that
mapping, passing an integer for <em>name</em> is also accepted. Availability:
Unix.</p>
<p>If the configuration value specified by <em>name</em> isn&#8217;t defined, <tt class="xref docutils literal"><span class="pre">None</span></tt> is
returned.</p>
<p>If <em>name</em> is a string and is not known, <a title="exceptions.ValueError" class="reference external" href="exceptions.html#exceptions.ValueError"><tt class="xref docutils literal"><span class="pre">ValueError</span></tt></a> is raised.  If a
specific value for <em>name</em> is not supported by the host system, even if it is
included in <tt class="docutils literal"><span class="pre">confstr_names</span></tt>, an <a title="exceptions.OSError" class="reference external" href="exceptions.html#exceptions.OSError"><tt class="xref docutils literal"><span class="pre">OSError</span></tt></a> is raised with
<a title="errno.EINVAL" class="reference external" href="errno.html#errno.EINVAL"><tt class="xref docutils literal"><span class="pre">errno.EINVAL</span></tt></a> for the error number.</p>
</dd></dl>

<dl class="data">
<dt id="os.confstr_names">
<tt class="descclassname">os.</tt><tt class="descname">confstr_names</tt><a class="headerlink" href="#os.confstr_names" title="Permalink to this definition">¶</a></dt>
<dd>Dictionary mapping names accepted by <a title="os.confstr" class="reference internal" href="#os.confstr"><tt class="xref docutils literal"><span class="pre">confstr()</span></tt></a> to the integer values
defined for those names by the host operating system. This can be used to
determine the set of names known to the system. Availability: Unix.</dd></dl>

<dl class="function">
<dt id="os.getloadavg">
<tt class="descclassname">os.</tt><tt class="descname">getloadavg</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getloadavg" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of processes in the system run queue averaged over the last
1, 5, and 15 minutes or raises <a title="exceptions.OSError" class="reference external" href="exceptions.html#exceptions.OSError"><tt class="xref docutils literal"><span class="pre">OSError</span></tt></a> if the load average was
unobtainable.  Availability: Unix.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="function">
<dt id="os.sysconf">
<tt class="descclassname">os.</tt><tt class="descname">sysconf</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#os.sysconf" title="Permalink to this definition">¶</a></dt>
<dd>Return integer-valued system configuration values. If the configuration value
specified by <em>name</em> isn&#8217;t defined, <tt class="docutils literal"><span class="pre">-1</span></tt> is returned.  The comments regarding
the <em>name</em> parameter for <a title="os.confstr" class="reference internal" href="#os.confstr"><tt class="xref docutils literal"><span class="pre">confstr()</span></tt></a> apply here as well; the dictionary that
provides information on the known names is given by <tt class="docutils literal"><span class="pre">sysconf_names</span></tt>.
Availability: Unix.</dd></dl>

<dl class="data">
<dt id="os.sysconf_names">
<tt class="descclassname">os.</tt><tt class="descname">sysconf_names</tt><a class="headerlink" href="#os.sysconf_names" title="Permalink to this definition">¶</a></dt>
<dd>Dictionary mapping names accepted by <a title="os.sysconf" class="reference internal" href="#os.sysconf"><tt class="xref docutils literal"><span class="pre">sysconf()</span></tt></a> to the integer values
defined for those names by the host operating system. This can be used to
determine the set of names known to the system. Availability: Unix.</dd></dl>

<p>The following data values are used to support path manipulation operations.  These
are defined for all platforms.</p>
<p>Higher-level operations on pathnames are defined in the <a title="Operations on pathnames." class="reference external" href="os.path.html#module-os.path"><tt class="xref docutils literal"><span class="pre">os.path</span></tt></a> module.</p>
<dl class="data">
<dt id="os.curdir">
<tt class="descclassname">os.</tt><tt class="descname">curdir</tt><a class="headerlink" href="#os.curdir" title="Permalink to this definition">¶</a></dt>
<dd>The constant string used by the operating system to refer to the current
directory. This is <tt class="docutils literal"><span class="pre">'.'</span></tt> for Windows and POSIX. Also available via
<a title="Operations on pathnames." class="reference external" href="os.path.html#module-os.path"><tt class="xref docutils literal"><span class="pre">os.path</span></tt></a>.</dd></dl>

<dl class="data">
<dt id="os.pardir">
<tt class="descclassname">os.</tt><tt class="descname">pardir</tt><a class="headerlink" href="#os.pardir" title="Permalink to this definition">¶</a></dt>
<dd>The constant string used by the operating system to refer to the parent
directory. This is <tt class="docutils literal"><span class="pre">'..'</span></tt> for Windows and POSIX. Also available via
<a title="Operations on pathnames." class="reference external" href="os.path.html#module-os.path"><tt class="xref docutils literal"><span class="pre">os.path</span></tt></a>.</dd></dl>

<dl class="data">
<dt id="os.sep">
<tt class="descclassname">os.</tt><tt class="descname">sep</tt><a class="headerlink" href="#os.sep" title="Permalink to this definition">¶</a></dt>
<dd>The character used by the operating system to separate pathname components.
This is <tt class="docutils literal"><span class="pre">'/'</span></tt> for POSIX and <tt class="docutils literal"><span class="pre">'\\'</span></tt> for Windows.  Note that knowing this
is not sufficient to be able to parse or concatenate pathnames &#8212; use
<a title="os.path.split" class="reference external" href="os.path.html#os.path.split"><tt class="xref docutils literal"><span class="pre">os.path.split()</span></tt></a> and <a title="os.path.join" class="reference external" href="os.path.html#os.path.join"><tt class="xref docutils literal"><span class="pre">os.path.join()</span></tt></a> &#8212; but it is occasionally
useful. Also available via <a title="Operations on pathnames." class="reference external" href="os.path.html#module-os.path"><tt class="xref docutils literal"><span class="pre">os.path</span></tt></a>.</dd></dl>

<dl class="data">
<dt id="os.altsep">
<tt class="descclassname">os.</tt><tt class="descname">altsep</tt><a class="headerlink" href="#os.altsep" title="Permalink to this definition">¶</a></dt>
<dd>An alternative character used by the operating system to separate pathname
components, or <tt class="xref docutils literal"><span class="pre">None</span></tt> if only one separator character exists.  This is set to
<tt class="docutils literal"><span class="pre">'/'</span></tt> on Windows systems where <tt class="docutils literal"><span class="pre">sep</span></tt> is a backslash. Also available via
<a title="Operations on pathnames." class="reference external" href="os.path.html#module-os.path"><tt class="xref docutils literal"><span class="pre">os.path</span></tt></a>.</dd></dl>

<dl class="data">
<dt id="os.extsep">
<tt class="descclassname">os.</tt><tt class="descname">extsep</tt><a class="headerlink" href="#os.extsep" title="Permalink to this definition">¶</a></dt>
<dd><p>The character which separates the base filename from the extension; for example,
the <tt class="docutils literal"><span class="pre">'.'</span></tt> in <tt class="docutils literal"><span class="pre">os.py</span></tt>. Also available via <a title="Operations on pathnames." class="reference external" href="os.path.html#module-os.path"><tt class="xref docutils literal"><span class="pre">os.path</span></tt></a>.</p>
<p>
<span class="versionmodified">New in version 2.2.</span></p>
</dd></dl>

<dl class="data">
<dt id="os.pathsep">
<tt class="descclassname">os.</tt><tt class="descname">pathsep</tt><a class="headerlink" href="#os.pathsep" title="Permalink to this definition">¶</a></dt>
<dd>The character conventionally used by the operating system to separate search
path components (as in <span class="target" id="index-455"></span><strong class="xref">PATH</strong>), such as <tt class="docutils literal"><span class="pre">':'</span></tt> for POSIX or <tt class="docutils literal"><span class="pre">';'</span></tt> for
Windows. Also available via <a title="Operations on pathnames." class="reference external" href="os.path.html#module-os.path"><tt class="xref docutils literal"><span class="pre">os.path</span></tt></a>.</dd></dl>

<dl class="data">
<dt id="os.defpath">
<tt class="descclassname">os.</tt><tt class="descname">defpath</tt><a class="headerlink" href="#os.defpath" title="Permalink to this definition">¶</a></dt>
<dd>The default search path used by <tt class="xref docutils literal"><span class="pre">exec*p*()</span></tt> and <tt class="xref docutils literal"><span class="pre">spawn*p*()</span></tt> if the
environment doesn&#8217;t have a <tt class="docutils literal"><span class="pre">'PATH'</span></tt> key. Also available via <a title="Operations on pathnames." class="reference external" href="os.path.html#module-os.path"><tt class="xref docutils literal"><span class="pre">os.path</span></tt></a>.</dd></dl>

<dl class="data">
<dt id="os.linesep">
<tt class="descclassname">os.</tt><tt class="descname">linesep</tt><a class="headerlink" href="#os.linesep" title="Permalink to this definition">¶</a></dt>
<dd>The string used to separate (or, rather, terminate) lines on the current
platform.  This may be a single character, such as <tt class="docutils literal"><span class="pre">'\n'</span></tt> for POSIX, or
multiple characters, for example, <tt class="docutils literal"><span class="pre">'\r\n'</span></tt> for Windows. Do not use
<em>os.linesep</em> as a line terminator when writing files opened in text mode (the
default); use a single <tt class="docutils literal"><span class="pre">'\n'</span></tt> instead, on all platforms.</dd></dl>

<dl class="data">
<dt id="os.devnull">
<tt class="descclassname">os.</tt><tt class="descname">devnull</tt><a class="headerlink" href="#os.devnull" title="Permalink to this definition">¶</a></dt>
<dd><p>The file path of the null device. For example: <tt class="docutils literal"><span class="pre">'/dev/null'</span></tt> for POSIX.
Also available via <a title="Operations on pathnames." class="reference external" href="os.path.html#module-os.path"><tt class="xref docutils literal"><span class="pre">os.path</span></tt></a>.</p>
<p>
<span class="versionmodified">New in version 2.4.</span></p>
</dd></dl>

</div>
<div class="section" id="miscellaneous-functions">
<span id="os-miscfunc"></span><h2>16.1.7. Miscellaneous Functions<a class="headerlink" href="#miscellaneous-functions" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="os.urandom">
<tt class="descclassname">os.</tt><tt class="descname">urandom</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#os.urandom" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a string of <em>n</em> random bytes suitable for cryptographic use.</p>
<p>This function returns random bytes from an OS-specific randomness source.  The
returned data should be unpredictable enough for cryptographic applications,
though its exact quality depends on the OS implementation.  On a UNIX-like
system this will query /dev/urandom, and on Windows it will use CryptGenRandom.
If a randomness source is not found, <a title="exceptions.NotImplementedError" class="reference external" href="exceptions.html#exceptions.NotImplementedError"><tt class="xref docutils literal"><span class="pre">NotImplementedError</span></tt></a> will be raised.</p>
<p>
<span class="versionmodified">New in version 2.4.</span></p>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../contents.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">16.1. <tt class="docutils literal"><span class="pre">os</span></tt> &#8212; Miscellaneous operating system interfaces</a><ul>
<li><a class="reference external" href="#process-parameters">16.1.1. Process Parameters</a></li>
<li><a class="reference external" href="#file-object-creation">16.1.2. File Object Creation</a></li>
<li><a class="reference external" href="#file-descriptor-operations">16.1.3. File Descriptor Operations</a></li>
<li><a class="reference external" href="#files-and-directories">16.1.4. Files and Directories</a></li>
<li><a class="reference external" href="#process-management">16.1.5. Process Management</a></li>
<li><a class="reference external" href="#miscellaneous-system-information">16.1.6. Miscellaneous System Information</a></li>
<li><a class="reference external" href="#miscellaneous-functions">16.1.7. Miscellaneous Functions</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="allos.html"
                                  title="previous chapter">16. Generic Operating System Services</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="io.html"
                                  title="next chapter">16.2. <tt class="docutils literal docutils literal"><span class="pre">io</span></tt> &#8212; Core tools for working with streams</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/library/os.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="io.html" title="16.2. io — Core tools for working with streams"
             >next</a> |</li>
        <li class="right" >
          <a href="allos.html" title="16. Generic Operating System Services"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="allos.html" >16. Generic Operating System Services</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; <a href="../copyright.html">Copyright</a> 1990-2009, Python Software Foundation.
      Last updated on Apr 15, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.1.
    </div>
  </body>
</html>